【问题标题】:IKVM and System.Core System.Runtime.CompilerServices.ExtensionAttributeIKVM 和 System.Core System.Runtime.CompilerServices.ExtensionAttribute
【发布时间】:2009-03-25 15:58:49
【问题描述】:

我正在使用最新版本的 IKVM 将 Java .jar 文件“编译”成 .NET DLL。一切正常,现在我尝试在 .NET 3.5 C# 项目中引用 DLL。

在我的 C# 项目中,我创建了一个静态“StringExtensions”类,其中包含一个字符串扩展方法。

由于某种原因,这似乎在昨天有效,但今天,我的扩展类出现构建错误(不确定昨天是如何工作的......)。

Missing compiler required member System.Runtime.CompilerServices.ExtensionAttribute..ctor

还有一个构建警告:

The predefined type 'System.Runtime.CompilerServices.ExtensionAttribute' is defined in multiple assemblies in the global alias; using definition from 'c:\TEMP\IKVM.Runtime.dll'

我发现 IKVM.Runtime.dll 和 System.Core.dll(3.5 版本)都有相同的类型:“System.Runtime.CompilerServices.ExtensionAttribute”

由于命名空间相同,我怎样才能让它与 ExtensionAttribute 的 System.Core 版本一起编译(或者我该如何解决这个问题)?

谢谢

【问题讨论】:

  • 我通过摆脱所有扩展方法来解决这个问题,但我仍然很好奇。似乎任何项目中存在 IKVM.Runtime.dll 都会导致扩展方法出现问题。

标签: c# .net extension-methods ikvm build-error


【解决方案1】:

更新到 IKVM 0.40.0.1 为我解决了这个问题。

【讨论】:

    【解决方案2】:

    如果您以 .Net 2.0 为目标,则只能在您自己定义此属性的情况下创建扩展方法。在您迁移到 .Net 3.5 之前,这非常有效。

    我不知道“IKVM”,但唯一真正的解决方法是要求他们删除属性和目标 3.5。

    【讨论】:

      【解决方案3】:

      我也有同样的问题。

      在我的情况下,问题在于程序集 Mono.Cecil。

      从本地引用迁移到 nuget,当我添加 NHibernate 引用时,包会自动添加此引用。

      此引用已被删除,并再次编译了我的项目。

      您需要了解此实现才能解决您的问题。必须删除两个程序集之一。

      这张图片取自 ILSpy (http://i.stack.imgur.com/Qyd5o.png)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-09-05
        • 1970-01-01
        • 2011-05-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-08
        相关资源
        最近更新 更多