Skip to content

Creating the native http handler throws BadImageFormatException #116698

Closed
@rolfbjarne

Description

@rolfbjarne

In a meastro bump for dotnet/dotnet from last week this is happening in our tests:

System.BadImageFormatException: Invalid usage of UnsafeAccessorAttribute.
   at System.Net.Http.HttpClientHandler.<CreateNativeHandler>g__CallNative|124_0()
   at System.Net.Http.HttpClientHandler.CreateNativeHandler()
   at System.Net.Http.HttpClientHandler..ctor()
   at System.Net.Http.HttpClient..ctor()

I'm guessing it's because if this change: da80937 (CC @jkoritzinsky)

This is the code in question:

private static HttpMessageHandler CreateNativeHandler()
{
return (HttpMessageHandler)CallNative();
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "GetHttpMessageHandler")]
[return: UnsafeAccessorType(NativeHandlerType)]
static extern object CallNative();
}

I think maybe the CallNative method should be this instead?

static extern HttpMessageHandler CallNative([UnsafeAccessorType(NativeHandlerType)] object type);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions