dnx icon indicating copy to clipboard operation
dnx copied to clipboard

Issues with System.Net.NetworkInformation on Linux CoreCLR

Open roji opened this issue 10 years ago • 15 comments

Some users of Npgsql & EF7 have run into issues adding migrations on Linux with CoreCLR, I've managed to narrow it down. I'm not sure how specific this is to System.Net.NetworkInformation or if I'm simply doing something silly...

Basically I have a simple DNX command as follows:

namespace Test
{
    public class Program
    {
        public static void Main(string[] args) {}

        static Program() {
            new PhysicalAddress(null);
        }
    }
}

The project.json:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

  "commands": {
    "test": "Test",
  },

  "frameworks": {
    "dnxcore50": {
      "dependencies": {
        "System.Collections": "4.0.11-beta-23516",
        "System.Console": "4.0.0-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Data.Common": "4.0.1-*",
        "System.Runtime": "4.0.21-*",
        "System.Threading": "4.0.11-beta-23516",
        "System.Net.NetworkInformation": "4.1.0-beta-*"
      }
    }
  }
}

Running the command with dnx test throws the following exception:

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

File name: 'System.Net.NetworkInformation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load the specified file.
File name: 'System.Net.NetworkInformation'
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at Test.Program..cctor()
   at Test.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at Microsoft.Dnx.ApplicationHost.Program.<>c__DisplayClass3_0.<ExecuteMain>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
System.IO.FileNotFoundException: Could not load the specified file.
File name: 'System.Net.NetworkInformation'
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)

On Windows CoreCLR this works great. Any ideas?

roji avatar Dec 15 '15 15:12 roji

This could be yet-another manifestation of RID-hell. Look in the project.lock.json and see if "runtime.linux.System.Net.NetworkInformation" is present in "libraries"

natemcmaster avatar Dec 21 '15 19:12 natemcmaster

What's the DNX version that you're using? Also, what's in your nuget.config (where are your packages restored when you do dnu restore?)

muratg avatar Dec 21 '15 19:12 muratg

Adding "runtime.linux.System.Net.NetworkInformation": "4.1.0-beta-*" in project.json fixes this for me

friism avatar Dec 21 '15 20:12 friism

Here's a repo with full repro: https://github.com/friism/dnx-3262-repro

friism avatar Dec 21 '15 20:12 friism

I am running rc1-update1 on ubuntu (AWS) connecting to AWS RDS PG using npgsql pkg.

Also, friism et al, I don't see why anyone should have to rely on anything "runtime.linux.*". The whole purpose of .NET Core cross platform is to not rely on anything Mono or "linux" specific. These are simple IL assemblies that get JITtered on the target OS by that compiler.

Also, why is anything still beta-23516? Shouldn't everything be 1.0.0-rc1? If you look here https://github.com/dotnet/corefx/tree/v1.0.0-rc1/src/System.Net.NetworkInformation You see for instance that System.Net.NetworkInformation is in fact on tag 1.0.0-rc1. Why then does DNX/DNU create project.json.lock files with 23516 everywhere?

This is very frustrating guys. This is a RC1 Update 1 and in fact has a "go-live" license with full support from MS. I would throw dedicated engs at these critical issues (ones that literally are show-stoppers where you can't run a one-line console app on Linux, which in turn translates to not being able to do a simple read from a Postgres DB on Linux due to these core lib deps). You will start to alienate the very people you're trying to attract through this whole effort. RC2 pails in comparison to getting RC1 working for what should be "happy path". Do you have unit tests for these? How can something like this slip through?

BTW frissm, after adding your runtime.linux thingy, I get

fail: Microsoft.Data.Entity.Query.Internal.NpgsqlQueryCompilationContextFactory[1] An exception occurred in the database while iterating the results of a query. System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

So this was what was supposed to be fixed in DNX/DNU via update 1 for cross plat publishing things like System.Net.Security.

thmulvany avatar Jan 01 '16 00:01 thmulvany

I was able to get it working by explicitly adding this dependency to dnxcore50:

"runtime.unix.System.Net.Security": "4.0.0-beta-23516"

Note that it's the unix runtime. I know nothing about how these JIT runtime-specific dependencies are resolved, but I assume that runtime.linux.System.Net.Information is looking for the equivalent runtime.linux.System.Net.Security, which doesn't exist.

snissim avatar Jan 04 '16 01:01 snissim

/cc @anurse

davidfowl avatar Jan 04 '16 01:01 davidfowl

Is this one of the "move to CLI" candidates @anurse? Or should we close this as no more work is planned on DNX...

muratg avatar Jan 04 '16 18:01 muratg

@snissim can you try removing that dependency and adding a dependency on Microsoft.NETCore.Platforms instead?

@muratg Probably not. It may not actually be an issue. The Microsoft.NETCore.Platforms dependency fixes it and is by design.

analogrelay avatar Jan 04 '16 18:01 analogrelay

@anurse right, now that you remind me :)

@snissim I'm pretty sure this would fix your issue.

muratg avatar Jan 04 '16 19:01 muratg

@anurse , @muratg so are you saying that nothing (no dependency tree) should ever use Sysetm.Net.NetworkInformation or System.Net.Security? Because that is the problem here. @friism was able to repro with a one-line app on Linux but the problem is that other nuget pkgs (e.g. NpgSql for EF7 provider for PostgreSQL) clearly add this dependency to their project.json files. Are you saying they (and everyone) should just add dep for Microsoft.NETCore.Platforms instead and stop using the others? This seems odd since those others are in fact nuget packages and part of base class libraries for .NET Core right?

thmulvany avatar Jan 04 '16 20:01 thmulvany

You need both Microsoft.NETCore.Platforms and System.Net.Security (and/or System.Net.NetworkInformation). The "Platforms" package is a special NuGet package that contains additional data used to locate platform-specific implementations.

analogrelay avatar Jan 04 '16 22:01 analogrelay

@anurse adding those dependencies doesn't solve the problem for me: https://github.com/friism/dnx-3262-repro/tree/try-fix

friism avatar Feb 01 '16 17:02 friism

I'm seeing the same issue as @friism (running 1.0.0-rc2-16357). Everything runs fine on my Mac but breaks going to Linux. I added the Microsoft.NETCore.Platform, System.Net.NetworkInformation and System.Net.Security references mentioned above in project.json and still get an error about loading NetworkInformation on Linux:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.NetworkInformation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

Added "runtime.linux.System.Net.NetworkInformation": "4.1.0-beta-*"and then I get this error:

File name: 'System.Net.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load the specified file.
File name: 'System.Net.Security'
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout)
   at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout)
   at Npgsql.NpgsqlConnector.Open()
   ....

Tried adding all of these into project.json but still get the System.Net.Security error above.

"runtime.linux.System.Net.NetworkInformation": "4.1.0-beta-*",
"Microsoft.NETCore.Platforms": "1.0.1-beta-*",
"System.Net.Security": "4.0.0-beta-*",
"System.Net.NetworkInformation": "4.1.0-beta-*"

Any ideas on how to get this going (hoping I need to do something simple or that I'm just missing something simple)? Appreciate it...been hitting wall after wall on this one. App can be found here:

https://github.com/DanWahlin/AspNetCorePostgreSQLDockerApp

DanWahlin avatar Feb 15 '16 01:02 DanWahlin

Right after posting I realized I missed @snissim's comment about adding runtime.unix.System.Net.Security. Had to add that plus runtime.linux.System.Net.NetworkInformation. That fixes it for me. None of the other stuff added above (such as Microsoft.NETCore.Platforms) worked though.

Hoping this gets a lot easier in the near future - burned a bunch of time trying to it going on Linux. But, happy I now have that option. :-)

DanWahlin avatar Feb 15 '16 02:02 DanWahlin