question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SetCookieHeaderValue - System.TypeLoadException: Could not load type Microsoft.Extensions.Primitives.InplaceStringBuilder'

See original GitHub issue

Description

This API is raising an exception because it cannot find type Microsoft.Extensions.Primitives.InplaceStringBuilder.

This happens both on .NET Framework 4.7.2 as well as .NET 6.0. I tried reference Microsoft.Net.Http.Headers 2.2.8, but the same exception is raised.

#region Assembly Microsoft.Net.Http.Headers, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 // D:\Git\AD-AggregatorService-Common\packages\microsoft.net.http.headers\2.2.0\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll // Decompiled with ICSharpCode.Decompiler 6.1.0.5902 #endregion

Test method Microsoft.Identity.Services.Http.UnitTest.CookieTest.Cookie_HeaderRoundtripping_Test threw exception: System.TypeLoadException: Could not load type ‘Microsoft.Extensions.Primitives.InplaceStringBuilder’ from assembly ‘Microsoft.Extensions.Primitives, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60’.

Stack Trace:  SetCookieHeaderValue.ToString() Cookie.ToSetCookieHeader() line 115 CookieTest.Cookie_HeaderRoundtripping_Test(String originalHeader, String expectedHeader) line 33

Reproduction Steps

        internal string ToSetCookieHeader()
        {
            SetCookieHeaderValue header = new SetCookieHeaderValue(this.Name, this.Value);
            header.Domain = this.Domain;
            header.Path = this.Path;
            header.MaxAge = this.MaxAge;
            header.Expires = this.Expires;
            header.HttpOnly = this.HttpOnly;
            header.Secure = this.Secure;
            header.SameSite = ConvertSameSiteModeAppToFramework(this.SameSite);

            return header.ToString();
        }

Expected behavior

SetCookieHeaderValue.ToString() should not throw.

Actual behavior

SetCookieHeaderValue.ToString() raises TypeLoadException.

Regression?

No response

Known Workarounds

No response

Configuration

.NET Framework 4.7.2 and .NET 6

Windows 11, x64

Other information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:23 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
joaocpaivacommented, Feb 7, 2022

That’s exactly the case.

@davidfowl any chances we could retain InPlaceStringBuilder, mark it as Obsolete instead? A quick search online finds us many threads about typeloadexception on InPlaceStringBuilder type … That would solve a lot of problems to the community.

2reactions
madelsoncommented, Feb 5, 2022

This issue is pretty annoying because it means you can run into problems whenever you pair one of the older packages with a newer version of Microsoft.Extensions.Primitives.

This situation is relatively easy to get yourself into if you have libraries that need to support .NET Framework and .NET Core, since .NET Framework only works with the older ASP.NET Core 2.x packages which rely on InPlaceStringBuilder.

If the InPlaceStringBuilder API had been retained or could be restored it would have (and still could) save us a lot of pain. Seems like it could just be marked as Obsolete.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - 'Could not load type 'Microsoft.Extensions.Primitives. ...
After setting everything up, I attempted to build my project and am getting the following exception: System.TypeLoadException: 'Could not load ...
Read more >
System.TypeLoadException: Could not load type Microsoft. ...
Description This API is raising an exception because it cannot find type Microsoft.Extensions.Primitives.InplaceStringBuilder.
Read more >
InplaceStringBuilder Struct (Microsoft.Extensions.Primitives)
InplaceStringBuilder in the Microsoft.Extensions.Primitives namespace. ... [System.Obsolete("This type is obsolete and will be removed in a future version.
Read more >
Error with AppSelfHostBase with .NET 5
Could not load type 'Microsoft.Extensions.Primitives.InplaceStringBuilder' from assembly 'Microsoft.Extensions.Primitives, Version=5.0.0.0, ...
Read more >
Could not load file or assembly 'Microsoft.Extensions. ...
Hi,. We provide the plugin using Batch Task API for Trados Studio 2021, and our customer reported above error.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found