当我尝试通过Mono.Cecil 0.9.3.0版读取Silverlight 5程序集时,出现以下异常:

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
....

发生这种情况是因为Silverlight项目中的引用是mscorlib 5.0.5.0,而GetCorlib函数似乎并未处理这些情况。

有解决这个问题的方法吗?

最佳答案

Cecil的默认解析器不处理Silverlight程序集。很容易修复。只需将自己的解析器传递给程序集,并确保它可以解析Silverlight程序集:

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

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

另外,我强烈建议您从0.9.3更新到较新的版本。

10-08 19:37