ikvmnet / ikvm

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

The type initializer for 'IKVM.Runtime.LibJvm' threw an exception, Object reference not set to an instance of an object #531

Closed mikeplacko closed 1 month ago

mikeplacko commented 1 month ago

I've run into this issue on a deployed .NET 4.7.2 windows service, when the first line of code that references the Java code is hit. This is a 32bit application. It builds correctly and debugging a unit test in Visual Studio works as expected, even when x86 is specifically targeted. Only a problem deployed.

All the IKVM folders exist in the solution for each targeted platform. java.dll, jvm.dll etc.

Checking through all the fusion logs, shows no issue binding to the IKVM dlls and no issue binding to the dll created by IKVM from the JAR file.

What else can I gather to help? I'm not sure if this is a new issue, or a duplicate of 525 but 525 looks to be closed with no solution provided (as best I could tell) so I'm opening it as a new issue. Was a change made because of 525 or just proposed?

System.TypeInitializationException: The type initializer for '' threw an exception. ---> System.TypeInitializationException: The type initializer for 'java.io.FileInputStream' threw an exception. ---> System.TypeInitializationException: The type initializer for 'IKVM.Runtime.LibJava' threw an exception. ---> System.TypeInitializationException: The type initializer for 'IKVM.Runtime.LibJvm' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object. at IKVM.Runtime.LibJvm..ctor() at IKVM.Runtime.LibJvm..cctor() --- End of inner exception stack trace --- at IKVM.Runtime.LibJava..ctor() at IKVM.Runtime.LibJava..cctor() --- End of inner exception stack trace --- at IKVM.Runtime.BootstrapClassLoader..ctor(RuntimeContext context) at IKVM.Runtime.RuntimeClassLoaderFactory.GetBootstrapClassLoader() at IKVM.Runtime.RuntimeClassLoaderFactory.GetClassLoaderWrapper(ClassLoader javaClassLoader) at IKVM.Runtime.RuntimeClassLoader.FromCallerID(CallerID callerID) at IKVM.Runtime.JNI.JNIFrame.GetFuncPtr(Object callerID, String clazz, String name, String sig) at java.io.FileInputStream.initIDs() at java.io.FileInputStream..cctor() --- End of inner exception stack trace --- at java.io.FileInputStream.() at java.lang.System.initializeSystemClass() at SysteminitializeSystemClass() at IKVM.Runtime.Accessors.Java.Lang.SystemAccessor.InvokeInitializeSystemClass() at IKVM.Runtime.JVM.Init() at IKVM.Runtime.RuntimeInit.Init() at .cctor() --- End of inner exception stack trace ---

mikeplacko commented 1 month ago

I should add, this is on Windows Server 2019.

wasabii commented 1 month ago

I'm assuming same as 525, which was closed by a commit. But not yet released. I need to get to finishing that.

mikeplacko commented 1 month ago

Maybe this cryptic message from the fusion log, which technically says it was successful, does point out a possible problem.

Assembly Binder Log Entry (5/30/2024 @ 7:07:12 AM)

The operation was successful. Bind result: hr = 0x1. Incorrect function.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable C:\Program Files (x86)\myapp\myservice.exe --- A detailed error log follows.

BEGIN : Native image bind. END : Incorrect function. (Exception from HRESULT: 0x00000001 (S_FALSE))

Assembly Binder Log Entry (5/30/2024 @ 7:07:12 AM)

The operation was successful. Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable C:\Program Files (x86)\myapp\myservice.exe --- A detailed error log follows.

=== Pre-bind state information === LOG: DisplayName = IKVM.Runtime, Version=8.8.0.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58 (Fully-specified) LOG: Appbase = file:///C:/Program Files (x86)/myapp LOG: Initial PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base = NULL LOG: AppName = myservice.exe Calling assembly : mycooljava.dll, Version=1.0.7.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58.

WRN: No matching native image found. LOG: IL assembly loaded from C:\Program Files (x86)\myapp\IKVM.Runtime.dll.

wasabii commented 1 month ago

Released 8.8.1. Check it out and see if it fixes your issue. It should.

mikeplacko commented 1 month ago

I'll do some deeper testing, but at first glance that appears to work. Thanks!