Runtime binding bug with .NET Standard Socket in a .NET Desktop console app


#1

I got a very simple test I am writing to do a client server communication sample in .NET Standard (1.4).
At runtime I got a type load exception as follows:

System.IO.FileNotFoundException: ‘Could not load file or assembly ‘System.Net.Sockets, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified.’

My .NET Standard server class

public class NetworkServerEcho
{
    public async void Start(int port)
    {
        var server = new TcpListener(new IPEndPoint(IPAddress.Any, port));
        while (true)
        {
            var connection = await server.AcceptSocketAsync();
            var t = Task.Run(() => HandleConnection(connection));
        }
    }
    private async void HandleConnection(Socket connection)
    {
        // ..
    }
}

Nuget dependency: System.Net.Sockets (4.3.0)

.NET Framework (4.6) / console test app

class Program
{
    static void Main(string[] args)
    {
        int port = 5434;
        var p = new HelloEcho();
        var ser = new NetworkServerEcho(p);
        ser.Start(port);
    }
}

What am I missing?

There is no System.Net.Sockets in the .NET Framework. I was expecting some binding redirect magic that would solve the problem. The .NET Standard System.Net.Sockets package declare it supports .NET Framework 4.6. Sockets are in System.dll on the desktop.


#2

Never mind, solved it, had to add those dependency in the .NET Framework app as well…
Makes perfect sense but I was confused for a while… All good now!


#3

I am having same problem.
How did you solve it. Please give the details
Thanks


.NET Foundation Website | Blog | Projects | Code of Conduct