Search code examples
java.netdeserializationclassnotfoundexceptionikvm

Class not found exception when using Java class in c#


I convert a java's class to dll using IKVM, by making a jar file for the this class and then I used IKVM to make the conversion operation. this operation is done successfully without errors or warnings. then I add the (DLL) with an 'IKVM.GNU.Classpath.dll' and 'IKVM.Runtime.dll' (DLLs) to my project. then I rebuilt the project, up to that point no errors, no warnings, no crashes happened. but when I tried to deserialized an arraylist of object from it is type, I get an exception is : java.lang.ClassNotFoundException: "MyClass" not found in java.lang.ClassLoader... my deserliazation. code is :

 object deserializedObject = null;               
 java.io.ObjectInputStream ina = new java.io.ObjectInputStream(new java.io.FileInputStream(@"D:\130043674485690000.txt"));
 deserializedObject = ina.readObject();
 ina.close();

Solution

  • First: you should use the current version of IKVM for new projects. The file name show that you use a very old version of IKVM.

    Second: you need to use all dlls from the IKVM. If all is working then you can remove some of the not used dlls.

    Third: if you does reference the classes of your dll/jar file statically then you need load it dynamically. See the wiki for details.