il-repack icon indicating copy to clipboard operation
il-repack copied to clipboard

AssemblyResolutionException System.Runtime

Open stoneman opened this issue 8 years ago • 3 comments

When trying to repack a console application on OS-X which includes the nuget package Microsoft.Extensions.DependencyInjection.Abstractions I get:

INFO: IL Repack - Version 2.0.10
INFO: Adding assembly for merge: ILRepackRepro/bin/Debug/ILRepackRepro.exe
INFO: Adding assembly for merge: ILRepackRepro/bin/Debug/Microsoft.Extensions.DependencyInjection.Abstractions.dll
ERROR: Failed to load assembly ILRepackRepro/bin/Debug/Microsoft.Extensions.DependencyInjection.Abstractions.dll
Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
  at ILRepacking.ILRepack.ReadInputAssembly (System.String assembly, Boolean isPrimary) <0x1c08a00 + 0x005d3> in <filename unknown>:0
  at ILRepacking.ILRepack.ReadInputAssemblies () <0x1c06cf8 + 0x000f7> in <filename unknown>:0
  at ILRepacking.ILRepack.Repack () <0x1bb16e0 + 0x0012f> in <filename unknown>:0
  at ILRepacking.Application.Main (System.String[] args) <0x1796f70 + 0x00123> in <filename unknown>:0

Doing the same on Windows works fine.

A simple solution demonstrating this issue can be found here: https://github.com/jonstoneman/ILRepackRepro

The OS-X repack command I am using is mono packages/ILRepack.2.0.10/tools/ILRepack.exe /out:ILRepackRepro.exe /wildcards ILRepackRepro/bin/Debug/ILRepackRepro.exe ILRepackRepro/bin/Debug/*.dll.

stoneman avatar Aug 15 '16 10:08 stoneman

I don't have a MAC platform to test on, do you think you can debug it through ? supposedly this code should add the right platform folders to the search paths (probably Facades subfolder is the one including System.Runtime.dll).

You can also give a try to adding /lib:FOLDER option, pointing to the right platform folder (which includes the above dll).

Thx

gluck avatar Aug 16 '16 08:08 gluck

Both Options.TargetPlatformDirectory and Options.TargetPlatformVersion are null. ResolveSearchDirectories() is not registering any directories with the GlobalAssemblyResolver so it still contains only . and bin.

When using /lib:/Library/Frameworks/Mono.framework/Versions/4.6.0/lib/mono/xbuild-frameworks/.NETPortable/v4.5 (which contains what I believe is the correct System.Runtime.dll) the repack command succeeds and the generated exe runs.

I've updated repack.sh in my repro and also modified the application so that DependencyInjection.Abstractions is being used at runtime.

> mono ./ILRepackRepro.exe
Hello World! a, b

stoneman avatar Aug 25 '16 13:08 stoneman

I just had a quite identical issue, and i managed to get it though thanks to this thread.

Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Diagnostics.Debug, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x000f7] in :0

I used a /lib switch to the correct folder and it worked fine. And like jonstonemann no problem under Windows.

mono "/Users/me/Projects/myproj/packages/ILRepack.2.0.12/tools/ILRepack.exe" /lib:/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks/.NETPortable/v4.5 /out:"my.Data.dll" "my.Data.dll" "fr/my.Data.resources.dll"

softlion avatar Dec 02 '16 13:12 softlion

This should work in the latest version

KirillOsenkov avatar Jan 07 '24 04:01 KirillOsenkov