mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 14:20:29 +01:00
Unable to use REST client with .Net Framework due to strong naming #210
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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?
@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):
https://github.com/canton7/RestEase/issues/50
@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.
@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
@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:
var api = RestClient.For("https://example.com");
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__80
1.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?
@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?
@adatanasov commented on GitHub (Mar 13, 2020):
StrongNamer doesn't help, nothing changes.
@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@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.
@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