0

My web project use .NET Framework 4.7.2 and use some references like

  • System.IO
  • System.Net
  • System.Net.Http
  • System.Net.Http.Formatting

My project works perfectly in local. However, when I publish my web project on a target directory (for online), and look what it contains in /bin/ :

  • System.IO is missing
  • System.Net is present
  • System.Net.Http is missing
  • System.Net.Http.Formattingis present

Therefore, when I use my website, I get the obvious error Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

All references have Copy Local = True in Properties but some dll are always ignored. If i copy the dlls from local directory to target directory i get the error Server Error in '/' Application. Cannot load a reference assembly for execution. Exception Details: System.BadImageFormatException: Cannot load a reference assembly for execution. Exactly the same problem as this one. However the delete/rebuild solution, or adding compilation options solution, doesn't work for me

What do I need to do to get these missing dlls to the destination folder?

Rod
  • 712
  • 2
  • 12
  • 36
  • Check your nuget manifest – Aluan Haddad Nov 08 '18 at 00:52
  • Yes? `System.IO` and `System.Net.Http` packages are installed – Rod Nov 08 '18 at 00:55
  • Is this one project or separate projects? If say you have the web app, then separate projects for say Data, Model etc, there could be reference diff between them – Papa Nov 08 '18 at 01:10
  • One solution using double projects. The .NET Web + source of one dll (not using `System.Net.Http` but using `System.IO`) – Rod Nov 08 '18 at 01:16
  • We had a similar issue recently and it was due to version of dlls being different from one project to the other being referenced – Papa Nov 08 '18 at 01:21

1 Answers1

1

Go to Solution Explorer on VS, open references tree, right click on the library(dll) and select properties on the menu. On properties box Copy Local should be True

Nick Mehrdad Babaki
  • 11,560
  • 15
  • 45
  • 70
  • As indicated in the original post, it's done. All references have `Copy Local = True` But it doesn't work. – Rod Nov 08 '18 at 01:00
  • `System.IO` and `System.Net.Http` packages are installed with the last version – Rod Nov 08 '18 at 01:07
  • 1
    One of your dlls is not updated and that causes the issue. Please make sure all the libraries are updated.It very common that libraries which are not compatible work fine in debug mode but give an error in release mode. And when you publish you are usually in release mode. See this link: https://learn.microsoft.com/en-us/dotnet/api/system.badimageformatexception?redirectedfrom=MSDN&view=netframework-4.7.2 – Nick Mehrdad Babaki Nov 08 '18 at 01:53
  • Also make sure the libraries are compatible with .net version you are using. – Nick Mehrdad Babaki Nov 08 '18 at 01:54
  • Works in local. The .NET Framework version can change after publishing ? – Rod Nov 08 '18 at 09:44
  • No, as long as server support the version you used. You don't need to install System.IO and System.Net.Http . They are parts of .net framework. maybe by installing the new packages, you made them incompatible with your project .net version – Nick Mehrdad Babaki Nov 08 '18 at 23:08