问题
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