c# - Mono.Cecil Exception 在分析.NET 4.5 版本的System.Xml DLL 时抛出,为什么?

标签 c# async-await mono.cecil

我使用的是 Mono.Cecil 0.9.5.3,在安装 VS2012 RC(这会导致 .NET 4.0 System.XML.DLL 被其 .NET 4.5 对应项替换)之后,我在一些系统中遇到了 System.ArugmentException迭代每个方法的自定义属性的代码。原因似乎是在某些情况下,AsyncStateMachine 属性的 ctor 参数(应该是 Type)为空。

下面的一段代码重现了它:

string path = Assembly.Load("System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089").Location;

AssemblyDefinition systemXmlAssembly = AssemblyDefinition.ReadAssembly(path);

var query =

    from ModuleDefinition module in systemXmlAssembly.Modules
    from TypeDefinition td in module.Types
    from MethodDefinition method in td.Methods
    from CustomAttribute att in method.CustomAttributes
    where method.Name == "System.Xml.IDtdParser.ParseInternalDtdAsync" &&
            att.AttributeType.Name == "AsyncStateMachineAttribute"
    select att;

CustomAttribute attribute = query.Single();

var args = attribute.ConstructorArguments; // <---- this line throws an ArgumentException

异常是从

抛出的
Mono.Cecil.ModuleDefinition.CheckFullName(string fullName = "")

我的问题是 - 这是 Mono.Cecil 或 System.Xml.DLL 中的错误吗?规范是否允许“空”类型作为 ctor 参数出现?

最佳答案

在我看来,这像是 Cecil 中的一个错误,从某种意义上说,Cecil 应该可以读取它而不会崩溃。

您可以在 https://github.com/jbevain/cecil 提交错误吗?并将 4.5 System.XML.dll 上传到某处?然后我会查看,并报告它是实际的 Cecil 问题,还是 System.XML 中编码错误的自定义属性。

更新:

这确实是 Cecil 的问题。现在已经在 master 中修复了。在发布新的 nuget 包之前,您必须自己构建 Cecil。谢谢!

关于c# - Mono.Cecil Exception 在分析.NET 4.5 版本的System.Xml DLL 时抛出,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10968929/

相关文章:

javascript - Javascript 异步函数的 'await' : generator's 'yield' vs. 'promise.then()' 的正确心理模型?

vb.net - 为什么我不能在语句中将 Await 括在括号中?

c# - 我可以从 MethodDefinition (Cecil) 获取 MethodInfo 吗?

c# - 将内部类更改为公共(public)类(CIL、Mono.Cecil)

c# - 替换方法的 MethodBody 中的指令

c# - 在不重启应用程序的情况下处理 URL 协议(protocol)

c# - HttpClient 的自定义用户代理?

c# - 我可以跨项目使用 "lock"吗?

c# - IComparer 接口(interface)用于比较委托(delegate),因为 IEqualityComparer 用于什么?

c# - 多个工作线程与一个使用异步/等待的工作线程