Mono.Cecil fails to process a Silverlight 5 assembly

北城余情 提交于 2019-12-22 10:29:03

问题


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:


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.



来源:https://stackoverflow.com/questions/9109506/mono-cecil-fails-to-process-a-silverlight-5-assembly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!