Unable to use REST client with .Net Framework due to strong naming #210

Closed
opened 2025-12-29 14:25:10 +01:00 by adam · 10 comments
Owner

Originally created by @vitaliydavydiak on GitHub (Sep 6, 2019).

Hi,

The proiblem seems to be due to this changes.
The WireMock.Net assembly has strong name while RestEase still not. The StrongNamer workaround does not seem to work anymore.
It means that even own WireMock.Net tests (FluentMockServerAdminRestClientTests) for net452 target would fail now. It is unable to load RestEase w/o strong name (as well as signed with StrongNamer). It seems to be some framework bug since it fails on reflection code from RestEase itself (which is already loaded w/o strong name).
Do you know any other workarounds for this or just have to deal with it?

Originally created by @vitaliydavydiak on GitHub (Sep 6, 2019). Hi, The proiblem seems to be due to this [changes](https://github.com/WireMock-Net/WireMock.Net/issues/160). The **WireMock.Net** assembly has strong name while **RestEase** still not. The [StrongNamer](https://github.com/dsplaisted/strongnamer) workaround does not seem to work anymore. It means that even own WireMock.Net tests (FluentMockServerAdminRestClientTests) for **net452** target would fail now. It is unable to load RestEase w/o strong name (as well as signed with StrongNamer). It seems to be some framework bug since it fails on reflection code from RestEase itself (which is already loaded w/o strong name). Do you know any other workarounds for this or just have to deal with it?
adam added the question label 2025-12-29 14:25:10 +01:00
adam closed this issue 2025-12-29 14:25:10 +01:00
Author
Owner

@StefH commented on GitHub (Sep 6, 2019):

I noticed the same issue for .net 452 tests indeed.

For the next major version 1.1.0 I'll remove the dependency on RestEase and move this to a new project, you can already take a look here:
https://github.com/WireMock-Net/WireMock.Net/pull/312

@StefH commented on GitHub (Sep 6, 2019): I noticed the same issue for .net 452 tests indeed. For the next major version 1.1.0 I'll remove the dependency on RestEase and move this to a new project, you can already take a look here: https://github.com/WireMock-Net/WireMock.Net/pull/312
Author
Owner

@StefH commented on GitHub (Sep 6, 2019):

https://github.com/canton7/RestEase/issues/50

@StefH commented on GitHub (Sep 6, 2019): https://github.com/canton7/RestEase/issues/50
Author
Owner

@vitaliydavydiak commented on GitHub (Sep 6, 2019):

Thanks for information. Looking forward to the new version. It does not seem that RestEase is going to have strong name in nearest future.

@vitaliydavydiak commented on GitHub (Sep 6, 2019): Thanks for information. Looking forward to the new version. It does not seem that RestEase is going to have strong name in nearest future.
Author
Owner

@StefH commented on GitHub (Sep 6, 2019):

@vitaliydavydiak
If you want, you can try preview 1.1.x on MyGet:
WireMock.Net.1.1.0-preview-01-ci-11870

@StefH commented on GitHub (Sep 6, 2019): @vitaliydavydiak If you want, you can try preview 1.1.x on MyGet: WireMock.Net.1.1.0-preview-01-ci-11870
Author
Owner

@adatanasov commented on GitHub (Mar 13, 2020):

I have the same issue with WireMock.Net.RestClient 1.1.10 and .NET 4.7.2.

Please follow the steps to reproduce:

  1. Create a new .NET framework console app targeting .NET 4.7.2
  2. Install WireMock.Net.RestClient nuget 1.1.10 (latest)
  3. Add this line in your Program.cs:
    var api = RestClient.For("https://example.com");
  4. Add usings:
    using RestEase;
    using WireMock.Client;

The project builds, but when try to execute (Ctrl+F5) the following error is returned:

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'RestEase, Version=1.4.10.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit)
at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T](MemberInfo element)
at RestEase.Implementation.ImplementationBuilder.<>c.b__44_0(Type x)
at RestEase.Implementation.ImplementationBuilder.d__801.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at RestEase.Implementation.ImplementationBuilder.BuildImplementationImpl(Type interfaceType)
at RestEase.Implementation.ImplementationBuilder.CreateImplementation[T](IRequester requester)
at RestEase.RestClient.ForT
at RestEase.RestClient.For[T](String baseUrl)
at TestWireMockRestClient.Program.Main(String[] args) in Program.cs:line 10

Is there something I can do to use the REST client at all?

@adatanasov commented on GitHub (Mar 13, 2020): I have the same issue with WireMock.Net.RestClient 1.1.10 and .NET 4.7.2. Please follow the steps to reproduce: 1. Create a new .NET framework console app targeting .NET 4.7.2 2. Install WireMock.Net.RestClient nuget 1.1.10 (latest) 3. Add this line in your Program.cs: var api = RestClient.For<IWireMockAdminApi>("https://example.com"); 4. Add usings: using RestEase; using WireMock.Client; The project builds, but when try to execute (Ctrl+F5) the following error is returned: Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'RestEase, Version=1.4.10.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044) at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit) at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit) at System.Reflection.CustomAttributeExtensions.GetCustomAttributes[T](MemberInfo element) at RestEase.Implementation.ImplementationBuilder.<>c.<BuildImplementationImpl>b__44_0(Type x) at RestEase.Implementation.ImplementationBuilder.<InterfaceAndChildren>d__80`1.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at RestEase.Implementation.ImplementationBuilder.BuildImplementationImpl(Type interfaceType) at RestEase.Implementation.ImplementationBuilder.CreateImplementation[T](IRequester requester) at RestEase.RestClient.For[T]() at RestEase.RestClient.For[T](String baseUrl) at TestWireMockRestClient.Program.Main(String[] args) in Program.cs:line 10 Is there something I can do to use the REST client at all?
Author
Owner

@StefH commented on GitHub (Mar 13, 2020):

This has been discussed with RestEase (https://github.com/canton7/RestEase/issues/50)

Maybe a workaround like https://github.com/dsplaisted/strongnamer can help you?

@StefH commented on GitHub (Mar 13, 2020): This has been discussed with RestEase (https://github.com/canton7/RestEase/issues/50) Maybe a workaround like https://github.com/dsplaisted/strongnamer can help you?
Author
Owner

@adatanasov commented on GitHub (Mar 13, 2020):

StrongNamer doesn't help, nothing changes.

@adatanasov commented on GitHub (Mar 13, 2020): StrongNamer doesn't help, nothing changes.
Author
Owner

@StefH commented on GitHub (Mar 15, 2020):

You could use Brutal.Dev.StrongNameSigner, see : https://github.com/WireMock-Net/WireMock.Net/wiki/Could-not-load-file-or-assembly-RestEase

@StefH commented on GitHub (Mar 15, 2020): You could use `Brutal.Dev.StrongNameSigner`, see : https://github.com/WireMock-Net/WireMock.Net/wiki/Could-not-load-file-or-assembly-RestEase
Author
Owner

@adatanasov commented on GitHub (Mar 15, 2020):

Thanks, that worked!
Just a note if somebody struggles with this too - I had to remove and add again the reference to the WireMock.RestClient.dll in the project after I install the Brutal.Dev.StrongNameSigner nuget.

@adatanasov commented on GitHub (Mar 15, 2020): Thanks, that worked! Just a note if somebody struggles with this too - I had to remove and add again the reference to the WireMock.RestClient.dll in the project after I install the Brutal.Dev.StrongNameSigner nuget.
Author
Owner

@StefH commented on GitHub (Mar 15, 2020):

Thanks I did add this to wiki.

BTW you can also create a dotnet core console app and change the framework to net472 ; this will also work and no need to use strongnamer

@StefH commented on GitHub (Mar 15, 2020): Thanks I did add this to wiki. BTW you can also create a dotnet core console app and change the framework to net472 ; this will also work and no need to use strongnamer
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#210