Recently one of our customer asked us
Q> I’m trying to compile some pure java code using VJ# (VS2005). Mostly it compiles fine, but there are problems with ClassLoaders. In particular, the original code calls getSystemClassLoader(), which doesn’t seem to exist in J#.
I’m a professional programmer but a Java newbie, so any help would be appreciated.
A> Unlike in J++ and Java, custom class loaders and security managers are not supported in J#.
The reason being that the way classloaders probe for classes in Java is different than what is used on .NET. In Java they use the notion of a CLASSPATH, while on .NET we lookup managed assemblies in the GAC, etc. Also there is the issue of how resources are represented in Java and on .NET, etc.
Security semantics too are different in Java and .NET. While J# does provide mappings, such components (security managers) need to be aware of Code Access Secuity semantics and all that.
So basically, J# does not support custom class loaders and security managers. J# uses a default classloader (named VJCClassLoader) that is not programmatically exposed. The method java.lang.Class.getClassLoader always returns null.
Applications using custom class loaders need to be modified to use the .NET Framework classes to now load managed assemblies. Applications can use methods like Assembly.Load or Assembly.LoadFrom to load an assembly and then retrieve a specific type from the loaded assembly. Our product docs on MSDN talk about in more detail. Also, the following link has a sample: http://msdn.microsoft.com/library/en-us/dv_vjsample/html/vjsamClassLoaderSampleModifyCustomClassLoaderForAssemblies.asp?frame=true