Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
vitaliydavydiak opened this issue Sep 6, 2019 · 10 comments
Closed
Labels

Comments

@vitaliydavydiak
Copy link
Contributor

vitaliydavydiak commented 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
Copy link
Collaborator

StefH commented 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:
#312

@StefH
Copy link
Collaborator

StefH commented Sep 6, 2019

canton7/RestEase#50

@vitaliydavydiak
Copy link
Contributor Author

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
Copy link
Collaborator

StefH commented 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 StefH added the invalid label Sep 19, 2019
@adatanasov
Copy link

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?

@StefH
Copy link
Collaborator

StefH commented Mar 13, 2020

This has been discussed with RestEase (canton7/RestEase#50)

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

@adatanasov
Copy link

StrongNamer doesn't help, nothing changes.

@StefH StefH reopened this Mar 15, 2020
@StefH StefH added question and removed invalid labels Mar 15, 2020
@StefH
Copy link
Collaborator

StefH commented 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 StefH closed this as completed Mar 15, 2020
@adatanasov
Copy link

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
Copy link
Collaborator

StefH commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants