ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.17k stars 110 forks source link

NetworkInterface, NullPointerException #379

Closed chenjing1294 closed 1 year ago

chenjing1294 commented 1 year ago

version: 8.6.1 platform: windows 10 x64

There will be no error during software debugging, but when the software is released, the operation will report an error:

dotnet publish -c Release --runtime win-x64 -p:PublishReadyToRun=true --self-contained true
System.TypeInitializationException: The type initializer for 'java.net.NetworkInterface' threw an exception.
 ---> java.lang.ExceptionInInitializerError: java.lang.NullPointerException
   --- End of inner exception stack trace ---
   at java.net.NetworkInterface.getNetworkInterfaces()

If I post using the command below, there is no problem:

dotnet publish -c Release --runtime win10-x64 -p:PublishReadyToRun=true --self-contained true
wasabii commented 1 year ago

Probably caused because a native library (libjava I'm guessing) is loaded in java.net.NetworkInterface's type initializer somewhere, and the java.dll and other files, during release, are copied into the bin/ directory directly, instead of being nested under runtimes/native. This is an odd property of the .NET SDK. When specifying a RID, the files are moved from runtimes/rid into ./. Might matter for Framework. Doesn't really matter for Core. And forces the app to know both. Also .deps.json is wrong. Totally weird.

That is fixed though. Boot library path now has the path to the IKVM.Runtime.dll included.