Closed trungnt2910 closed 5 months ago
So, this is a real problem I've been struggling with for quite awhile: finding the right place to initialize the BCL, without leaving something uncovered, and without causing a bootstrapping issue of some kind.
In real-Java, this is easy. It happens after the VM is initialized, before any user code is run, always, kicked off by java.exe. Since all initialization of the VM goes through this one entry point: java.exe.
But, not the case in IKVM, where people can write plain ol' .NET code, and then randomlly call into java classes without going through a centralized loader. Everything I've tried so far has ended up with some sort of bootstrapper issue. Such as a static getting initialized where it shouldn't, and that static needing other things to be initialized, which end up needing that very first static initialized.
Maybe making every Java class a child of java.lang.Object
and then do something in the java.lang.Object
static constructor may help?
Another potential solution is to have a module initializer in the IKVM dll, which is run when the IKVM dll is loaded.
Module initializer causes an issue because of our cyclic dependency between runtime and Java. Runtime causes Java to be loaded before runtime is ready. This is at least fixable, as it's the current plan to remove the cycle. But not today.
Static ctor on object causes doesn't work because if you start the initialization on one objects static ctor, then it doesn't get called twice to initialize.
This should be resolved in 8.7.4 which is inprogress.
Works for me with v8.7.5
, thank you
Suppose that I create a sample
IKVM.NET.Sdk
project using this Java class:And, I reference this from a C# console application:
I would encounter an exception like this, when trying to access
System.out
:A workaround is to create a dummy object before calling
main()
: