Hi Jeroen, Thanks, the generated byte code now loads. On 02/08/2012 15:40, Jeroen Frijters wrote: > It looks like a "simple" class loader issue. It just can't find the base class. Where is com.saxonica.bytecode.GeneratedCode supposed to come from? The base class exists as an abstract class in the product > If it is in a statically (ikvmc) compiled assembly then it looks like that assembly is not referenced from your main (test) executable. I don't know if Visual Studio 2010 does anything different here from 2008, but it is possible (I'm currently traveling and don't have access to Visual Studio 2010). Not Sure. but it would be interesting to see what the difference is. If you don't actually use an assembly the C# compiler will not include a reference to an assembly (even though it is referenced in the project settings), but I believe this was true of 2008 as well. The workaround for that is to do something like this in your test driver main executable: > GC.KeepAlive(typeof(com.saxonica.bytecode.GeneratedCode)); This also worked. > You could also explicitly pass the class loader of com.saxonica.bytecode.GeneratedCode as the parent class loader of the class loader you construct to load the generated class. That is a more general solution as it does not require the system class loader (i.e. the main executable) to be able to reference the base class. Managed to get the class loader from the parent class. Kind regards, O'Neil Hi O'Neil, It looks like a "simple" class loader issue. It just can't find the base class. Where is com.saxonica.bytecode.GeneratedCode supposed to come from? If it is in a statically (ikvmc) compiled assembly then it looks like that assembly is not referenced from your main (test) executable. I don't know if Visual Studio 2010 does anything different here from 2008, but it is possible (I'm currently traveling and don't have access to Visual Studio 2010). If you don't actually use an assembly the C# compiler will not include a reference to an assembly (even though it is referenced in the project settings), but I believe this was true of 2008 as well. The workaround for that is to do something like this in your test driver main executable: GC.KeepAlive(typeof(com.saxonica.bytecode.GeneratedCode)); You could also explicitly pass the class loader of com.saxonica.bytecode.GeneratedCode as the parent class loader of the class loader you construct to load the generated class. That is a more general solution as it does not require the system class loader (i.e. the main executable) to be able to reference the base class. Regards, Jeroen ________________________________________ From: Dr O'Neil Delpratt [oneil@saxonica.com] Sent: Thursday, August 02, 2012 1:26 PM To: Jeroen Frijters Cc: Michael Kay Subject: Re: NoClassDefFoundError thrown Hi Jeroen, Thanks for all your help. I managed to successfully get the IKVM to build with the debug WriteLine statement. Using the statement 'global::System.Console.WriteLine(x);' we get the the trace of where the exception is thrown from in IKVM, which is given below. What we are doing in Saxon is generating bytecode using ASM on the fly, which works in Java and .NET 2.XX but not in .NET 4.XX. Any ideas? I have attached a generated bytecode which was used to solve a IKVM bug sometime ago, hopefully it can be used to reproduce the error we are getting. I will continue to investigate around the DynamicTypeWrapper class and in particular what is happening in the LoadTypeWrapper method. Using the statement you suggested: 'global::System.Console.WriteLine(x);' in openjdk.cs we get the the trace of where the exception is thrown from in IKVM, which is given below. at IKVM.Internal.DynamicTypeWrapper.LoadTypeWrapper(ClassLoaderWrapper classLoader, String name) at IKVM.Internal.DynamicTypeWrapper..ctor(ClassFile f, ClassLoaderWrapper classLoader) at IKVM.Internal.DynamicClassLoader.DefineClassImpl(Dictionary`2 types, ClassFile f, ClassLoaderWrapper classLoader, Object protectionDomain) at IKVM.Internal.ClassLoaderWrapper.DefineClassCritical(ClassFile f, Object protectionDomain) at IKVM.Internal.ClassLoaderWrapper.DefineClass(ClassFile f, Object protectionDomain) at IKVM.NativeCode.java.lang.ClassLoader.defineClass1(ClassLoader thisClassLoader, String name, Byte[] b, Int32 off, Int32 len, Object pd, String source) and the stack trace reported back to Visual studio is the following: java.lang.NoClassDefFoundError was unhandled Message=com.saxonica.bytecode.GeneratedCode Source=IKVM.Runtime StackTrace: at IKVM.NativeCode.java.lang.ClassLoader.defineClass1(ClassLoader thisClassLoader, String name, Byte[] b, Int32 off, Int32 len, Object pd, String source) at java.lang.ClassLoader.defineClass1(String , Byte[] , Int32 , Int32 , ProtectionDomain , String ) at java.lang.ClassLoader.defineClass(String name, Byte[] b, Int32 off, Int32 len, ProtectionDomain protectionDomain) at java.lang.ClassLoader.defineClass(String name, Byte[] b, Int32 off, Int32 len) at net.sf.saxon.dotnet.DotNetPlatform$1.findClass(String ) at java.lang.ClassLoader.loadClass(String name, Boolean resolve) at java.lang.ClassLoader.loadClass(String name) at com.saxonica.bytecode.util.CompilerService.makeClass(ClassWriter writer, String className) at com.saxonica.bytecode.util.CompilerService.compileToByteCode(Expression expr, String objectName, Int32 evaluationModes) at com.saxonica.bytecode.LetExpressionCompiler.compileCommonExpr(CompilerService compiler, Expression exp, Int32 evaluationMode, Int32 refCount) at com.saxonica.bytecode.LetExpressionCompiler.compileToPush(CompilerService compiler, Expression expression) at com.saxonica.bytecode.util.CompilerService.compileToPush(Expression expr) at com.saxonica.bytecode.ForExpressionCompiler.compileToPush(CompilerService compiler, Expression expression) at com.saxonica.bytecode.util.CompilerService.compileToPush(Expression expr) at com.saxonica.bytecode.BlockCompiler.compileToPush(CompilerService compiler, Expression expression) at com.saxonica.bytecode.util.CompilerService.compileToPush(Expression expr) at com.saxonica.bytecode.ElementCreatorCompiler.compileToPush(CompilerService compiler, Expression expression) at com.saxonica.bytecode.ToPushCompiler.compileToIterator(CompilerService compiler, Expression expression) at com.saxonica.bytecode.util.CompilerService.compileToIterator(Expression expr) at com.saxonica.bytecode.util.CompilerService.compileToByteCode(Expression expr, String objectName, Int32 evaluationModes) at com.saxonica.expr.ee.OptimizerEE.compileToByteCode(Expression expr, String objectName, Int32 evaluationMethods) at net.sf.saxon.query.XQueryExpression..ctor(Expression exp, Executable exec, QueryModule mainModule, Configuration config) at net.sf.saxon.query.QueryParser.makeXQueryExpression(String query, QueryModule mainModule, Configuration config) at net.sf.saxon.query.StaticQueryContext.compileQuery(String query) at Saxon.Api.XQueryCompiler.Compile(String query) at SaxonEE_bytecode_test.Program.TestXQueryCompilation() in C:\Users\ond1\Desktop\SaxonEE-bytecode-test\SaxonEE-bytecode-test\Program.cs:line 24 at SaxonEE_bytecode_test.Program.Main() in C:\Users\ond1\Desktop\SaxonEE-bytecode-test\SaxonEE-bytecode-test\Program.cs:line 37 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: Hi, It can't find the windows resource compiler. Building from a Visual Studio command prompt should fix that, but you can also simply ignore this error, the important files have been built at this point. Sent from my Windows Phone From: Dr O'Neil Delpratt Sent: 8/1/2012 9:13 To: Jeroen Frijters Subject: Re: NoClassDefFoundError thrown Hi Jeroen, I am getting this build error which indicates a missing file. Any ideas?: [nant] C:\work\software\ikvm-ikvm\ikvm\jvm\jvm.build Buildfile: file:///C:/work/software/ikvm-ikvm/ikvm/jvm/jvm.build Target framework: Microsoft .NET Framework 4.0 Target(s) specified: JVM Function platform::is-win32 is deprecated. Use the is-windows function instead. version: [copy] Copying 1 file to 'C:\work\software\ikvm-ikvm\ikvm\jvm\jvm.rc'. JVM: [rc] Compiling "C:\work\software\ikvm-ikvm\ikvm\jvm\jvm.rc" to "C:\work\software\ikvm-ikvm\ikvm\jvm\jvm.res". BUILD FAILED - 0 non-fatal error(s), 1 warning(s) C:\work\software\ikvm-ikvm\ikvm\jvm\jvm.build(20,10): 'rc' failed to start. The system cannot find the file specified On 01/08/2012 15:03, Jeroen Frijters wrote: The javac in your path must be Java 7. ________________________________________ From: Dr O'Neil Delpratt [oneil@saxonica.com] Sent: Wednesday, August 01, 2012 3:36 PM To: Jeroen Frijters Subject: Re: NoClassDefFoundError thrown Hi Jeroen, Thanks again. I am now almost there with a complete build. However I am getting lots of errors related to the Openjdk. I am using the zip file from your website: openjdk-7u4-stripped.zip Any ideas? Just to mention a few of the error: ..... [exec] sun\nio\ch\FileDispatcherImpl.java:255: