1

I am making a class library in .NET Standard, which I wish to be usable from Windows and Android. However, when I try to reference the project or the project output directly, then I get AssemblyNotFoundExceptions at runtime, with a different one for each NuGet package that my .NET Standard project references. Adding each NuGet package to every project that references the .NET Standard project makes this problem go away, but it feels like an unsustainable solution. What is the best way to resolve the dependencies in a .NET Standard project? I am using Visual Studio 2017, my console project is .NET 4.7, and my .NET Standard project is .NET Standard 1.6.

I have already referenced NETStandard.Library from my console project, but it does not work. Type such as System.ValueTuple still throw exceptions when I attempt to use them.

Right now, the exception I am getting upon attempting to run my program is this:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime.Serialization.Formatters, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

Which makes sense, as I use serialization in my .NET Standard library.

JRB
  • 1,943
  • 1
  • 10
  • 9
laptou
  • 6,389
  • 2
  • 28
  • 59
  • There can be a need to add necessary assembly redirection in your app.config file. Post the exact exception you got please. – Lex Li May 09 '17 at 00:42
  • @LexLi `System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime.Serialization.Formatters, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.' ` – laptou May 09 '17 at 00:52
  • the actual assembly in your bin folder might be 4.3.0.0. Check that and learn how to redirect. – Lex Li May 09 '17 at 03:01
  • Are you referencing the output dll directory or do you use a project reference? – Martin Ullrich May 13 '17 at 18:50
  • @MartinUllrich I have tried both, and neither work. – laptou May 13 '17 at 19:36
  • Can you reproduce it using a new netstandard library + console app or does it just fail on Xamarin? Does the resulting .exe.config contain binding redirects? – Martin Ullrich May 13 '17 at 19:44
  • @MartinUllrich I was never using Xamarin, I am indeed already using a netstandard library and a console app. For now, I have simply resorted to installing all the NuGet packages on both projects, but I will try uninstalling them and checking the exe.config later. – laptou May 13 '17 at 20:02
  • @333 can you check if the answer of this helps you? (force msbuild to generate binding redirects): http://stackoverflow.com/questions/43995432/could-not-load-file-or-assembly-microsoft-extensions-dependencyinjection-abstrac/43996389#43996389 – Martin Ullrich May 19 '17 at 21:24

1 Answers1

0

Have you tried to use .Net Standard 1.4 for your referenced library?

bxu
  • 1
  • 1