使用anon-method和委托错误重新编译OpenXmlSdkTool.Core DLL

时间:2013-08-31 10:24:40

标签: c# delegates decompiling anonymous-methods

我正在研究OpenXmlSdkTools v2.5,并在OpenXmlSdkTools.Core.DLL中有一个潜行峰值,并将其保存为带有ILSpy的c#项目。

虽然这个问题是有效的,但OpenXmlSdkTools.Core.DLL是一种快速重现我遇到的问题的方法。

当我尝试编译单个类库项目时,我得到两个关于程序集“System.Xaml”的missng引用的错误。例如:

  

类型'System.Windows.Markup.IQueryAmbient'在一个。中定义   未引用的程序集。您必须添加对程序集的引用   “System.Xaml

     

类型'System.Windows.Markup.IUriContext'在程序集中定义   没有引用。您必须添加对程序集的引用   “System.Xaml

所以我添加了参考号。

之后我就陷入了我希望的最后一次编译错误,我无法弄明白。

  

无法将匿名方法转换为输入'System.Delegate',因为它   不是代表   键入C:\ TFS \ ABC \ src \ OpenXmlSdkTool.Core \ DocumentFormat.OpenXml.Tools \ ApplicationExtensions.cs   10

以下是代码:

using System;
using System.Windows;
using System.Windows.Threading;
namespace DocumentFormat.OpenXml.Tools
{
    public static class ApplicationExtensions
    {
        public static void DoEvents(this Application application)
        {
            application.Dispatcher.Invoke(DispatcherPriority.Background, delegate
            {
            });
        }
    }
}

我陷入困境并且困惑于它的反编译DLL应该很容易再次重新编译。你认为我添加Xaml引用会导致这个问题吗?如果Core.DLL是类库项目并且ILSpy没有将它包含在csproj文件中,为什么我需要添加Xaml引用?

我在这里查看了所有其他问题并出现了同样的错误,但没有一个真的有帮助。

更新

当您添加System.Xaml.dll作为项目的参考时。接口在那里声明。这是doc

所以现在我在Catch22中,如果我添加Xaml dll它将解决前2个错误,但之后会导致其他错误。

1 个答案:

答案 0 :(得分:2)

在我的计算机上重现问题后,我发现了http://staceyw1.wordpress.com/2007/12/22/they-are-anonymous-methods-not-anonymous-delegates/(引自Convert this delegate to an anonymous method or lambda)。

向Action添加强制转换解决了问题

application.Dispatcher.Invoke(DispatcherPriority.Background, (Action)delegate
        {
        });

但可能还有其他解决方案。

相关问题