5

There are TONS of posts, blogs, articles, etc... explaining all of this confusing stuff with regard to .Net/.NetCore/.NetStandard and I have read many of them.

Here is the issue, I have a Windows 10 UWP app and I need to reference a library that I created. I first created the library as a NetCore library but I could not reference that from my UWP app (which is confusing because UWP uses .Net Core but the .Net Core library I created assumed this was for ASP.NET?).

So, then I tried to create the library as a PCL library and targeted ONLY Windows 10 UWP (which it then forces you to Windows 8.1 because they are the same). With this type of library I am confident I would be able to reference it from my UWP app but it caused me to lose too many .Net namespaces that I could not get the library to build.

Finally, I then selected the link, in the project properties, to target the .Net Standard instead. I selected .Net Standard 1.4 and suddenly, I had all the namespaces I needed available to me and I was able to build my library. I am also able to successfully add it as a reference to my UWP app.

However, I am getting the following 6 exceptions and they don't tell me too much about the root cause so I can fix it.

Exceptions

So, my main question is, can you reference a .Net Standard 1.4 library in your UWP app? Second, any ideas what these exceptions mean?

Thanks!

EDIT - I have uploaded both csproj files here:csproj files

codeGeek
  • 259
  • 4
  • 17
Michael Bedford
  • 1,742
  • 20
  • 48
  • Please include the .csproj of the UWP project and of the library if possible. – Scott Chamberlain May 01 '17 at 23:34
  • A .NET Core class library can only be consumed by .NET Core applications, currently only console apps and web apps. UWP happens to inspire .NET Core development, and shares some tooling (like NuGet/project.json). However, UWP is Windows only and is not categorized as part of .NET Core. PCL is the past, so no comment on it. The only question you have is why the NuGet package triggers the errors. – Lex Li May 02 '17 at 00:50
  • @ScottChamberlain I have added a link to the csproj files. Thank you for looking in to this, it is all very confusing. Please note, the UWP app is a test utility I threw together so it is very light which should help eliminate causes for this issue. Thanks! – Michael Bedford May 02 '17 at 16:56
  • Also, it would appear that you cannot reference .Net Standard 1.4 from a UWP app. I form that assumption because I created a brand new class library, converted it to .Net Standard 1.4 and then tried to reference it from my UWP app and I am getting the same 6 errors as in my screenshot in my OP. There is absolutely no code in this library and the only two reference it has are the two created when I created the library, Microsoft.NetCore.Portable.Compatability and NetStandard.Libarary. – Michael Bedford May 02 '17 at 17:19

1 Answers1

2

Okay, I found that answer but it was based mainly on this answer which I did not see before posting my question due to search terms (I have literally spent over a day searching and trying to find an answer).

Answer that helped:

Here is a summary:

  1. .NetStandard 1.4 is supported by UWP.

  2. By default, VS 2015 Update 3 template for a UWP project imports Microsoft.NetCore.UniversalWindowsPlatform version 5.1.0. I am sure the VS 2017 template will start off with a newer version, 5.1.0 is fairly old. So, based on the answer linked above, I updated (using NuGet) to the newest version allowed by VS 2015 Update 3 which at the time of this answer, is version 5.2.3. There is a 5.3.x version but it requires VS 2017.

  3. Finally, I modified the project.json in my UWP project to import the netstandard1.4 framework. It looks like this:

    "frameworks": {
      "uap10.0": {
        "imports": "netstandard1.4"
      }    
    

And, with those simple steps, I can get the UWP project to build and those 6 errors above go away.

Hope this helps!

Community
  • 1
  • 1
Michael Bedford
  • 1,742
  • 20
  • 48