1

I created in VS2017 two C# projects:

  • .NET Standard 1.5 library
  • .NET Framework 4.6.2 Console application. (implements Standard 1.5)

I added the reference to the library, but cannot access types from it.
Compiler just complains that it cannot find neither namespace nor class.

Moreover, Studio allows to start the application and then throws:

System.IO.FileNotFoundException: '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.'

So, what am I doing wrong?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137
  • 4.6.1 implements only .NET Standard 1.4 so I'm not sure you can reference 1.5 library. – Tóth Tibor Mar 12 '17 at 19:17
  • @TóthTibor Sorry, mistyped. 4.6.2, not 4.6.1 Corrected my question. – Pavel Voronin Mar 12 '17 at 19:21
  • Are these empty projects or do they have code? – Tóth Tibor Mar 12 '17 at 19:22
  • @TóthTibor I just added a single class to the library. – Pavel Voronin Mar 12 '17 at 19:24
  • It's really weird because I can reproduce your bug but after I tried to downgrade the versions to 1.4 and 4.6.1 it worked good. Then I upgrade to 1.5 and 4.6.2 and this is also worked which was bad before... – Tóth Tibor Mar 12 '17 at 19:33
  • @TóthTibor Well, it started building solution without errors after restarting VS. Thow exception is still thrown. – Pavel Voronin Mar 12 '17 at 19:34
  • I can't provide more help. It's a bug for me too (VS2017 RTM). :( – Tóth Tibor Mar 12 '17 at 19:36
  • @TóthTibor Yep, found one more. It can hang on 'Build started...' =) – Pavel Voronin Mar 12 '17 at 19:39
  • I'm not sure if this is the same problem but I posted [this on GitHub](https://github.com/dotnet/corefx/issues/17014). –  Mar 12 '17 at 22:39
  • I'm pretty sure you need to bring your Framework project down to net46. That is what [the compatibility matrix](https://github.com/dotnet/standard/blob/master/docs/versions.md) says. –  Mar 12 '17 at 22:47
  • @TóthTibor where do you read 4.6.1 implements .NET Standard 1.4? Link in my comment above indicates 4.6 supports up to Standard 1.6. –  Mar 12 '17 at 22:53
  • 1
    @Sam He probably read it [here](https://learn.microsoft.com/en-us/dotnet/articles/standard/library) – Pavel Voronin Mar 13 '17 at 06:11
  • @Sam, assembly version mismatch is another possible cause, but as davidsh at GitHub commented, the assembly facade is also needed, which is covered by my answer. – Lex Li Mar 13 '17 at 12:27
  • 1
    already answered here (with some more details) http://stackoverflow.com/questions/41535341/using-net-standard-1-5-lib-in-net-4-6-2-misses-system-runtime-4-1-0-0 – Boas Enkler Mar 13 '17 at 12:38

1 Answers1

3

You have to add NETStandard.Library to your reference list of the traditional project. Then all related assemblies would appear in your output folder so that runtime exceptions won't occur. (If you do need anything more than .NET Standard Library, also add that package to this traditional project).

At this stage, it is a limitation we have to get used to. Ultimately Microsoft should find a better way to address it.

(Note that you might also need assembly redirection in app.config, if there are version number mismatch.)

Lex Li
  • 60,503
  • 9
  • 116
  • 147