New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.DllNotFoundException thrown when calling System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces #1733

Closed
Ceeten opened this Issue Nov 28, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@Ceeten

Ceeten commented Nov 28, 2018

Good morning.

I've been trying to experiment with Blazor a bit and try out some things that I would want the browser to be able to do for me.

One of those things is execute some stuff on the network by using the System.Net.NetworkInformation namespace.
So I've added the Nuget Package to the Blazor project and simply used it in the default scaffolded blazor project:

@using System.Net.NetworkInformation;
@using System;


@page "/counter"

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" onclick="@IncrementCount">Click me</button>

@functions {
    int currentCount = 0;

    void IncrementCount()
    {
        var test =  NetworkInterface.GetAllNetworkInterfaces();
        System.Console.WriteLine(test);
    }
}

Problem is when I click the button, the next exception is thrown and I see this in the browser console:

blazor.webassembly.js:1 Uncaught (in promise) Error: System.TypeInitializationException: The type initializer for 'System.Net.NetworkInformation.SystemNetworkInterface' threw an exception. ---> System.DllNotFoundException: libc
  at (wrapper managed-to-native) System.Platform.uname(intptr)
  at System.Platform.CheckOS () <0x1de1250 + 0x00030> in <693d0b3e5dd34843b73a58a39499184e>:0 
  at System.Platform.get_IsMacOS () <0x1de1008 + 0x0000a> in <693d0b3e5dd34843b73a58a39499184e>:0 
  at System.Net.NetworkInformation.UnixNetworkInterfaceFactoryPal.Create () <0x1de08e8 + 0x00014> in <693d0b3e5dd34843b73a58a39499184e>:0 
  at System.Net.NetworkInformation.NetworkInterfaceFactoryPal.Create () <0x1de0458 + 0x00000> in <693d0b3e5dd34843b73a58a39499184e>:0 
  at System.Net.NetworkInformation.NetworkInterfaceFactory.Create () <0x1de0378 + 0x00000> in <693d0b3e5dd34843b73a58a39499184e>:0 
  at System.Net.NetworkInformation.SystemNetworkInterface..cctor () <0x1de0288 + 0x00000> in <693d0b3e5dd34843b73a58a39499184e>:0 
   --- End of inner exception stack trace ---
  at Microsoft.JSInterop.DotNetDispatcher.InvokeSynchronously (System.String assemblyName, System.String methodIdentifier, System.Object targetInstance, System.String argsJson) <0x1d88a50 + 0x001bc> in <af36ed9192be4a95b907125ccf0c1e59>:0 
  at Microsoft.JSInterop.DotNetDispatcher.BeginInvoke (System.String callId, System.String assemblyName, System.String methodIdentifier, System.Int64 dotNetObjectId, System.String argsJson) <0x1d84710 + 0x00088> in <af36ed9192be4a95b907125ccf0c1e59>:0 
  at (wrapper managed-to-native) System.Platform.uname(intptr)
  at System.Platform.CheckOS () <0x1de1250 + 0x00030> in <693d0b3e5dd34843b73a58a39499184e>:0 
  at System.Platform.get_IsMacOS () <0x1de1008 + 0x0000a> in <693d0b3e5dd34843b73a58a39499184e>:0 
  at System.Net.NetworkInformation.UnixNetworkInterfaceFactoryPal.Create () <0x1de08e8 + 0x00014> in <693d0b3e5dd34843b73a58a39499184e>:0 
  at System.Net.NetworkInformation.NetworkInterfaceFactoryPal.Create () <0x1de0458 + 0x00000> in <693d0b3e5dd34843b73a58a39499184e>:0 
  at System.Net.NetworkInformation.NetworkInterfaceFactory.Create () <0x1de0378 + 0x00000> in <693d0b3e5dd34843b73a58a39499184e>:0 
  at System.Net.NetworkInformation.SystemNetworkInterface..cctor () <0x1de0288 + 0x00000> in <693d0b3e5dd34843b73a58a39499184e>:0 
   --- End of inner exception stack trace ---
  at Microsoft.JSInterop.DotNetDispatcher.InvokeSynchronously (System.String assemblyName, System.String methodIdentifier, System.Object targetInstance, System.String argsJson) <0x1d88a50 + 0x001bc> in <af36ed9192be4a95b907125ccf0c1e59>:0 
  at Microsoft.JSInterop.DotNetDispatcher.BeginInvoke (System.String callId, System.String assemblyName, System.String methodIdentifier, System.Int64 dotNetObjectId, System.String argsJson) <0x1d84710 + 0x00088> in <af36ed9192be4a95b907125ccf0c1e59>:0 
    at endInvokeDotNetFromJS (http://localhost:50480/_framework/blazor.webassembly.js:1:26867)
    at Object.invokeJSFromDotNet (http://localhost:50480/_framework/blazor.webassembly.js:1:26288)
    at _mono_wasm_invoke_js_marshalled (http://localhost:50480/_framework/wasm/mono.js:1:175302)
    at wasm-function[1450]:935
    at wasm-function[762]:25085
    at wasm-function[762]:23853
    at wasm-function[762]:23853
    at wasm-function[762]:23853
    at wasm-function[762]:24468
    at wasm-function[762]:24468

I am running the latest VS (15.9.2) with the latest SDK on Windows. Anybody that can give me an Idea of what I'm doing wrong here ?

@SteveSandersonMS

This comment has been minimized.

Member

SteveSandersonMS commented Nov 28, 2018

GetAllNetworkInterfaces is not going to work, because the browser doesn't expose any information about network interfaces to JS/WASM code.

The intended principle is that, for any parts of the netstandard API surface that aren't applicable inside a browser, Mono should throw PlatformNotSupportedException. However the Mono team is still working on making the base class library (BCL) ready for WebAssembly and there are many cases where it throws a different exception instead, such as you see here. If you are keen, you could report this case to http://github.com/mono/mono, however you don't really need to because they will be reviewing every BCL API eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment