jbevain / cecil

Cecil is a library to inspect, modify and create .NET programs and libraries.
MIT License
2.76k stars 627 forks source link

.NET Framework 4.8.1 - Failed to resolve assembly: netstandard, Version=2.0.0.0 #901

Open fandrei opened 1 year ago

fandrei commented 1 year ago
            var resolver = new DefaultAssemblyResolver();
            var asm = resolver.Resolve(new AssemblyNameReference("netstandard", new Version("2.0")));
            var module = asm.MainModule;

This code successfully resolves the assembly when executed from a .NET 6 app, but it fails in a .NET 4.8.1 app:

Failed to resolve assembly: 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null'
pengweiqhca commented 1 year ago

Missing PublicKeyToken.

fandrei commented 1 year ago

@pengweiqhca that doesn't matter.

lextm commented 1 year ago

DefaultAssemblyResolver is not able to resolve many assemblies if you check its source code (and BaseAssemblyResolver). You need to add search directories to guide it.

You might read https://github.com/jbevain/cecil/discussions/802 to study a similar case.