【问题标题】:GuidAttribute error in AssemblyInfo.csAssemblyInfo.cs 中的 GuidAttribute 错误
【发布时间】:2016-07-06 15:01:06
【问题描述】:

我使用 .NET Core RC2 编写了一个库,现在我将其更新为 RTM。迁移中没有问题,除了一个。出于某种原因,Visual Studio(以及 dotnet 实用程序)在 AssemblyInfo.cs 中引发有关 Guid 的错误:

“GuidAttribute”类型存在于两者中 'System.Runtime.InteropServices.PInvoke,版本=4.0.0.0, 文化=中立,PublicKeyToken=b03f5f7f11d50a3a' 和 'System.Runtime.InteropServices,版本=4.1.0.0

我不确定这里发生了什么。

这就是我的 AssemblyInfo.cs 的样子:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("My.Library")]
[assembly: AssemblyTrademark("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f89c2fd8-91f3-4f5a-87b6-094ee19712cf")]

都是通用的,由 Visual Studio 生成。

我的 project.json 也很简单:

{
  "title": "My Library",
  "version": "1.0.0-*",
  "dependencies": {
    "NETStandard.Library": "1.6.0",
    "AWSSDK.Core": "3.2.4.1-beta",
    "AWSSDK.EC2": "3.2.4.1-beta",
    "System.Net.Primitives": "4.0.11",
    "System.Threading.Tasks": "4.0.11",
    "System.Collections": "4.0.11"
  },
  "frameworks": {
    "netstandard1.5": {
      "imports": [ "dnxcore50", "portable-net45+win8" ]
    }
  },
  "buildOptions": {
    "xmlDoc": true
  }
}

我真的不确定发生了什么,并且我开始认为该错误可能具有误导性。有没有我犯的错误但看不到?我该如何调试?

【问题讨论】:

  • 我看到过类似这样的奇怪错误,这些错误已通过清除 bin/obj/artifacts 文件夹(摆脱任何以前的构建)并确保您只是构建源文件。这对你有用吗?
  • 很遗憾没有:(

标签: .net asp.net-core .net-core


【解决方案1】:

.Net Core 开发过程中存在 System.Runtime.InteropServices.PInvoke 库,将GuidAttribute 类型移至其中。但是this library was removed before the 1.0 version

问题在于 AWSSDK.Core 3.2.4.1-beta 依赖它。

我认为解决这个问题的最好方法是升级到 AWSSDK.Core 和 AWSSDK.EC2 3.2.5-beta,它们依赖于 .Net 标准库的 1.0 版本,所以他们没有这个问题。

另一个可能的解决方案是从您的代码中删除 GuidAttribute(或将其隐藏在 #if 后面),因为您很可能不需要它。

【讨论】:

  • 修复了它。我没有意识到 AWSSDK.Core 3.2.4 和 3.2.5 之间有如此大的变化,也没有考虑升级依赖项。我的错。非常感谢您的详细解释。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-09
  • 2014-12-08
  • 2011-01-03
  • 1970-01-01
  • 2012-12-24
相关资源
最近更新 更多