System.Runtime(.net 4.6)和mscorlib(.net Standard 1.6)

时间:2017-01-21 11:14:55

标签: .net mscorlib .net-standard

我开发了一个简单的.net标准库。

然后我在.net 4.6项目中引用了这个程序集,基本上工作正常。

但是当我尝试使用bool(或Guid)参数调用此.net标准库中的方法时,我收到此错误:

  

无法转换来源类型' bool [mscorlib,Version = 4.0.0.0,   Culture = neutral,PublicKeyToken = b77a5c561934e089]'目标类型   ' bool [System.Runtime,Version = 4.1.0.0,Culture = neutral,   公钥= b03f5f7f11d50a3a]&​​#39;

这些类型在两个程序集中定义:mscorlib和System.Runtime ...我该如何解决这个问题?

更新

这是一个显示此错误的非常简单的示例:

.net Portable Library - >通过属性选项卡

转换为.NET Standard
public class MyClass
{
    public void CallMe(Guid guid)
    {
        //so something
    }
}

Project.json

{
  "supports": {},
  "dependencies": {
    "Microsoft.NETCore.Portable.Compatibility": "1.0.1",
    "NETStandard.Library": "1.6.0"
  },
  "frameworks": {
    "netstandard1.6": {}
  }
}

我还必须将它添加到我的csproj-File中,在外部它根本不起作用:

  <PropertyGroup>
    <NuGetTargetMoniker>.NETStandard,Version=v1.6</NuGetTargetMoniker>
  </PropertyGroup>

net 4.6.1项目(直接通过dll文件引用.net标准库(项目引用不起作用)

public class Class1
    {
        private void Call()
        {
            var c = new MyClass();
            c.CallMe(Guid.NewGuid());
        }
    }

这就是错误信息: enter image description here

1 个答案:

答案 0 :(得分:2)

@Jon Skeet感谢您的帮助。

问题是.net Framework-Version和.NET Standardversion之间不兼容。

列表可以在这里找到: https://docs.microsoft.com/en-us/dotnet/articles/standard/library

相关问题