ikvmnet / ikvm

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

IKVMc 8.7.1: : Object reference not set to an instance of an object #446

Closed sergey-tihon closed 1 year ago

sergey-tihon commented 1 year ago

Something changed in IKVMc usage (or I just did it wrong). Appreciate any suggestions

I am migrating the build to the newer version of IKVM and run it on Windows 11 23H2 22631.2506

From To
tools IKVM-8.2.1-tools-ikvmc-net461.zip IKVM-8.7.1-tools-net472-win-x64.zip
bin IKVM-8.2.1-bin-net461.zip IKVM-8.7.1-tools-net472-win-x64.zip

Where I till ikvmc:

tools-ikvmc-net472\ikvmc.exe  -runtime:bin-net472/IKVM.Runtime.dll -version:4.2.0.2 stanford-segmenter-4.2.0.jar -out:stanford-segmenter-4.2.0.dll

I see the null reference error:

IKVM.Tools.Importer (8.7.1+Branch.tags-8.7.1.Sha.e4ff2051f79fc0849223e953f257ca37e2a0f854)
Copyright © 2023 Jeroen Frijters, Windward Studios, Jerome Haltom, Shad Storhaug

Error: core library not found

*** INTERNAL COMPILER ERROR ***

PLEASE FILE A BUG REPORT FOR IKVM.NET WHEN YOU SEE THIS MESSAGE

IKVM.Tools.Importer, Version=8.7.1.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
4.0.30319.42000 64-bit

System.NullReferenceException: Object reference not set to an instance of an object.
   at IKVM.Runtime.AttributeHelper.GetEditorBrowsableNever() in /_/src/IKVM.Runtime/AttributeHelper.cs:line 402
   at IKVM.Runtime.RuntimeByteCodeJavaType.JavaTypeImpl.LinkMethod(RuntimeJavaMethod mw) in /_/src/IKVM.Runtime/RuntimeByteCodeJavaType.JavaTypeImpl.cs:line 2487
   at IKVM.Runtime.RuntimeJavaMethod.DoLinkMethod() in /_/src/IKVM.Runtime/RuntimeJavaMethod.cs:line 339
   at IKVM.Runtime.RuntimeJavaMethod.Link(LoadMode mode) in /_/src/IKVM.Runtime/RuntimeJavaMethod.cs:line 329
   at IKVM.Runtime.RuntimeByteCodeJavaType.JavaTypeImpl.Finish() in /_/src/IKVM.Runtime/RuntimeByteCodeJavaType.JavaTypeImpl.cs:line 1187
   at IKVM.Tools.Importer.RuntimeImportByteCodeJavaType.Finish() in /_/src/IKVM.Tools.Importer/RuntimeImportByteCodeJavaType.cs:line 116
   at IKVM.Runtime.DynamicClassLoader.FinishAll() in /_/src/IKVM.Runtime/DynamicClassLoader.cs:line 412
   at IKVM.Tools.Importer.CompilerClassLoader.Compile(RuntimeContext context, StaticCompiler compiler, String runtimeAssembly, List`1 optionsList) in /_/src/IKVM.Tools.Importer/CompilerClassLoader.cs:line 2547
   at IKVM.Tools.Importer.IkvmImporterInternal.Compile(String[] args) in /_/src/IKVM.Tools.Importer/IkvmImporterInternal.cs:line 196
   at IKVM.Tools.Importer.IkvmImporterInternal.Execute(String[] args) in /_/src/IKVM.Tools.Importer/IkvmImporterInternal.cs:line 111
wasabii commented 1 year ago

Need to specify all of the -reference items that would make up the BCL of the desired target framework set. Specifically in this case, it can't find the 'core library', which will be mscorlib.dll for Framework.

For instance, if you want to link to the targeting pack for .NET 4.8, on Windows x64, you'd find the mscorlib.dll assembly in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8, and the other assemblies in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades, and add them as -reference items to the command.

Though they can be installed elsewhere. And you might not want to link to reference assemblies. For instance, if you intend to link to the Microsoft.NETFramework.ReferenceAssemblies NuGet package, you would need to specify the assemblies from that. Up to you.

sergey-tihon commented 1 year ago

Hmm... got it, thank you.

sergey-tihon commented 1 year ago

@wasabii is there an replacement for ikvm.@internal.ClassLiteral<T>.Value?

image

wasabii commented 1 year ago

IKVM.Runtime.ClassLiteral, though it isn't intended to be used outside of IKVM.

What's going on here?

sergey-tihon commented 1 year ago

There are plenty of API inside Stanford CoreNLP that get Class as a parameter and use it as a key to look up some metadata.

ikvm.@internal.ClassLiteral<T>.Value was a nice hack to get Class from Type and they use it for lookup.

image

sergey-tihon commented 1 year ago

java.lang.Class can be cast to System.Type

Here I need another way around, System.Type -> java.lang.Class

wasabii commented 1 year ago

You can cast System.Type to java.lang.Class.

wasabii commented 1 year ago

The operation is different though, but probably compatible for your situation.

ClassLiteral is more of a quick storage cache. Relying on the natire of generics for each concrete generic having it's own field. Used internally to cache instances, where it makes sense (and is possible). But Type->Class or Class->Type operations are more complex than that.

For instance, (Class)typeof(object) actually results in the Class for java.lang.Object. And (Class)typeof(java.lang.Object) results in the Class for System.Object. And the cast operator handles arrays, ghost interfaces, etc. And it will return null for impossible operations, such as casting a pointer type to a Class, managed reference, or generics, since those have no Java representation.

Think of the cast operator as answering this question: "if I were to have a .NET type T, and I wanted to pass it to a Java method, in Java, what would the Class of that parameter be?"

GeorgeS2019 commented 12 months ago

https://github.com/yakivyusin/SimpleNetNlp/issues/23#issuecomment-1837149332