Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have developed an simple .net Standard-Library.

then I referenced this assembly in an .net 4.6 Project which basically works fine.

But when I try to call a method in this .net Standard-library with an bool (or Guid)-parameter I'm getting this error:

Cannot convert source type 'bool [mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]' to target type 'bool [System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]'

These Types are defined in both-assemblies: mscorlib and System.Runtime...how can I fix this?

UPDATE

here is an very simple example to Show this error:

.net Portable Library --> converted to .NET Standard via the property-tab

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": {}
  }
}

I also had to add this to my csproj-File, outerwise it doesn't work at all:

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

net 4.6.1 Project (referenced the .net Standard-library directly via the dll-file (Project-reference is not working)

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

And that is the error-message: enter image description here

like image 350
Tobias Koller Avatar asked Mar 31 '26 00:03

Tobias Koller


1 Answers

@Jon Skeet Thank you for your help.

The problem was an incompatibility between the .net Framework-Version and the .NET Standardversion.

The list can be found here: https://learn.microsoft.com/en-us/dotnet/articles/standard/library

like image 112
Tobias Koller Avatar answered Apr 02 '26 13:04

Tobias Koller