2

I am trying to figure out what I could be doing wrong in this sample project. I am getting an error when my net462 application references a netstandard1.5 library. The application has a dependency on "System.Collections.Immutable": "1.3.0", which targets NetStandard 1.0 according to Nuget. The library depends on "NETStandard.Library": "1.6.0".

Am I setting up either of these projects wrong? I would greatly appreciate any insight on this...

Here are their project.json :

app:

{
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "SomeLibrary": "1.0.0-*"
  },
  "frameworks": {
    "net462": {
      "dependencies": {
        "System.Collections.Immutable": "1.3.0" 
      }
    }
  },
  "version": "1.0.0-*"
}

Library

{
  "buildOptions": {
    "allowUnsafe": true
  },
  "dependencies": {
  },
  "frameworks": {
    "netstandard1.5": {
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    }
  },
  "version": "1.0.0-*"
}

All the library has is this interface:

using System.Collections.Generic;

namespace SomeLibrary
{
    public interface SomeInterface
    {
        int GetValue(KeyValuePair<string, int> somePair);
    }
}

The app implements this interface and makes a call the concrete class:

public class Program
{
    public static void Main(string[] args)
    {
        var concreteObject = new ConcreteImplementation();
        var answer = concreteObject.GetValue(new KeyValuePair<string, int>("key", 33));
        Console.WriteLine(answer);
    }
}


class ConcreteImplementation : SomeInterface
{
    public int GetValue(KeyValuePair<string, int> somePair)
    {
        return somePair.Value;
    }
}

If I try to run the app, here is the error that I get:

{"Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.":"System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"}

Stack: at ErrorExample.Consumer..ctor() at ErrorExample.Program.Main(String[] args) in ..\ErrorExample\src\ErrorExample\Program.cs:line 11

What am I missing here? Thanks!

Athari
  • 33,702
  • 16
  • 105
  • 146
  • That says you cannot use `net462` with `netstandard1.5`. Try to use `net462` for your library. – Tân Nov 29 '16 at 13:02
  • I thought they were supposed to be compatible, as seen on the matrix in this article (https://learn.microsoft.com/en-us/dotnet/articles/standard/library), or maybe I am interpreting the matrix wrong... – dan_rozenberg Nov 29 '16 at 17:09

1 Answers1

1

I'm not quite sure about why this is happening, but using netstandard1.4 as a TFM for your library project would resolve your issue. In other words, project.json of your library should look like that:

{
  "buildOptions": {
    "allowUnsafe": true
  },
  "dependencies": {
  },
  "frameworks": {
    "netstandard1.4": { // <-- replace "netstandard1.5" with "netstandard1.4" or lower
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    }
  },
  "version": "1.0.0-*"
}

And as a current general rule of thumb: avoid using netstandard1.5 and netstandard1.6: use netstandard1.4 and lower according to your requirements until you are explicitly forced to. Wait for release of netstandard2.0. You may read the details about it in the MSDN blog artible about .NET Standard. And here's a FAQ.

Deilan
  • 4,740
  • 3
  • 39
  • 52
  • You are right: if I change it to netstandard1.4 things start working again. However, in my actual project I do not have control over the netstandard that is being implemented. However, knowing that it works in 1.4 might be a hint of the underlying problem. Ultimately, I still want to know what is the fundamental problem here. Thanks! – dan_rozenberg Nov 29 '16 at 16:48
  • I'd suggest you posting the issue at [Microsoft's coreclr repository](https://github.com/dotnet/coreclr) then. – Deilan Nov 29 '16 at 17:05
  • I got a very similar problem here: http://stackoverflow.com/questions/41535341/using-net-standard-1-5-lib-in-net-4-6-2-misses-system-runtime-4-1-0-0 any hint ? – Boas Enkler Jan 09 '17 at 13:25