SetCookieHeaderValue - System.TypeLoadException: Could not load type Microsoft.Extensions.Primitives.InplaceStringBuilder'
See original GitHub issueDescription
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:
- Created 2 years ago
- Reactions:1
- Comments:23 (15 by maintainers)
Top GitHub Comments
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.
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 asObsolete
.