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

AssemblyResolutionException on attempt to build project using Puresharp #16

Open
kjaworski opened this issue May 17, 2021 · 1 comment

Comments

@kjaworski
Copy link

kjaworski commented May 17, 2021

The following error appears during building a project in VS:

7>Unhandled Exception: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
7>   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
7>   at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
7>   at IPuresharp.Authority.Modules(AssemblyDefinition assembly)
7>   at IPuresharp.Authority.Modules(AssemblyDefinition assembly)
7>   at IPuresharp.Authority.Include(AssemblyDefinition assembly, Assembly[] dependencies)
7>   at IPuresharp.Authority.Manage(TypeDefinition type, MethodDefinition method)
7>   at IPuresharp.Authority..ctor(TypeDefinition type)
7>   at IPuresharp.Program.Manage(TypeDefinition type)
7>   at IPuresharp.Program.Manage(String assembly)
7>   at IPuresharp.Program.Main(String[] arguments)

And VS logs this error:
The command ""%USERPROFILE%\.nuget\packages\IPuresharp\5.0.5\build\net452\IPuresharp.exe" "C:\Sources\path_to_My.Internal.Company.Assembly.dll"" exited with code -532462766. My.Internal.Company.Assembly C:\Users\myuser\.nuget\packages\ipuresharp\5.0.5\build\netcoreapp2.1\IPuresharp.targets 11

@DreadLordMikey
Copy link

DreadLordMikey commented Jan 4, 2023

If you're building a classic .NET application, this may be due to IPureSharp's Program.Manage method not adding all possible packages folders below the solution root to the DefaultAssemblyResolver.

For example, if you are building a .NET classic solution in a folder named Foo containing a MyFoo project folder and a packages folder, the Foo\packages folder will not be added to the DefaultAssemblyResolver, and therefore not scanned for packages, leading to a compile-time exception.

You can see the source code for Program.Manage here. The DefaultAssemblyResolver only contains the folders %PROGRAM_FILES%\dotnet\shared and %USER_PROFILE%\.nuget\packages, in that order.

The folders in the DefaultAssemblyResolver are evaluated in the order in which they are added to it. %PROGRAM_FILES%\dotnet\shared was scanned and no matches were found. The scan proceeded to %USER_PROFILE%\.nuget\packages and no matches were found. Finally, as no more directories were in the resolver, the AssemblyResolutionException was thrown using the last directory scanned.

Ideally, any packages folders between the assembly that is the target of the weaving operation and the solution root should be added before %PROGRAM_FILES%\dotnet\shared and %USER_PROFILE%\.nuget\packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants