0

My Web API is running on IIS 8.5 with .NET 4.6.1 installed. I added a new controller that connects to PostgreSQL database using Npgsql NuGet package.

Now I'm getting an exception on every request to that controller in production (on my local machine everything works as expected):

Could not load file or assembly 'System.Net.Sockets, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Net.Sockets, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at Npgsql.NpgsqlConnector.d__154.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine) at Npgsql.NpgsqlConnector.ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationToken) at Npgsql.NpgsqlConnector.d__152.MoveNext()

I changed Enable 32-Bit Applications to true in the application pool, but that did not solve the problem.

I'm using Visual Studio 2015.

UPDATE

If I add System.Net.Sockets but not version 4.2.0.0 I get an exception:

Could not load file or assembly 'System.Net.Sockets, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

FIL
  • 1,148
  • 3
  • 15
  • 27
  • In the error: `The system cannot find the file specified`. Does System.Net.Sockets ship with your software? – Martin Dec 19 '19 at 11:43
  • check this out, https://stackoverflow.com/questions/47149345/could-not-load-file-or-assembly-system-net-http – MrLu Dec 19 '19 at 11:43
  • @Martin It does not. There is no `System.Net.Sockets` library in by `bin` folder on my machine (where API works). I could not find that library in my system. In NuGet, there is a package, but there is no v. 4.2.0. – FIL Dec 19 '19 at 11:46
  • @FIL You may need to install it on the server in order for your application to work there – Martin Dec 19 '19 at 11:57
  • can you share ur web.config? – Gauravsa Dec 19 '19 at 12:25
  • is there anything which says bindingRedirect? – Gauravsa Dec 19 '19 at 12:27
  • @Gauravsa Each `dependentAssembly` in `assemblyBinding` has `bindingRedirect`. About 20 entries... If I add `System.Net.Sockets` as `dependentAssembly` with `bindingRedirect` to v.4.3.0, my API stops working (error 500). – FIL Dec 19 '19 at 12:31
  • ok. can you try removing "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files" and restart the application – Gauravsa Dec 19 '19 at 12:33
  • I tried, still the same error. – FIL Dec 19 '19 at 12:38
  • try to set load user profile to true in iis application pool advance setting or rebuild and redeploy ALL Dependents DLL files. – Jalpa Panchal Dec 20 '19 at 09:27

0 Answers0