Mono.Cecil fails to process a Silverlight 5 assemb

2019-05-18 07:58发布

When I am trying to read a Silverlight 5 assembly via Mono.Cecil version 0.9.3.0, I am getting the following exception:

System.NotSupportedException: Version not supported: 5.0.5.0
------   
at Mono.Cecil.BaseAssemblyResolver.GetCorlib(AssemblyNameReference reference) in C:\programming\mono.cecil\jbevain-cecil-5df660e\Mono.Cecil\BaseAssemblyResolver.cs:line 200
------  
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name) in C:\programming\mono.cecil\jbevain-cecil-5df660e\Mono.Cecil\BaseAssemblyResolver.cs:line 117
....

It happens because the reference in the Silverlight project is to mscorlib 5.0.5.0 while the GetCorlib function doesn't seem to be handling these cases.

Is there a solution to this issue?

1条回答
在下西门庆
2楼-- · 2019-05-18 08:51

Cecil's default resolver doesn't handle Silverlight assemblies. It's easy to fix. Just pass your own resolver to your assemblies, and make sure it can resolve Silverlight assemblies:

var resolver = new DefaultAssemblyResolver ();
resolver.AddSearchDirectory ("path/to/silverlight/assemblies");

var assembly = AssemblyDefinition.ReadAssembly (
    assemblyFile,
    new ReaderParameters { AssemblyResolver = resolver });

Also, I strongly suggest you update from 0.9.3 to a newer release.

查看更多
登录 后发表回答