Re: [Ikvm-developers] Dynamic loading woes (again)
Brought to you by:
jfrijters
|
From: Jeroen F. <je...@su...> - 2007-02-09 06:45:40
|
Michael Kay wrote:
> I've moved to 0.32.0.0 and I'm having dynamic loading trouble again.
>
> This is what I'm doing:
>
> Transform.exe is C# code, it links statically to saxon8.dll, which is
> cross-compiled from Java.
>
> On invocation, Transform.exe does
>
> Assembly asm =3D Assembly.Load("saxon8sa");
>
> which succeeds. (saxon8sa.dll is also cross-compiled from Java).
>
> Transform.exe then calls code within saxon8.dll which attempts to do a
> dynamic load of the class
> com.saxonica.validate.SchemaAwareConfiguration,
> which is one of the classes in saxon8sa.dll; and the dynamic
> load fails with
> java.lang.ClassNotFoundException.
>
> The loading strategy is first to call
>
> loader =3D Thread.currentThread().getContextClassLoader();
> loader.loadClass("com.saxonica.validate.SchemaAwareConfiguration");
>
> and if that fails, to use Class.forName("...").
>
> This was working before on 0.30.0.0 - though the IKVM version
> isn't the only thing that has changed.
>
> Any ideas?
The issue here is that 0.32 uses a fixed (and predictable) class loading mo=
del and no longer searches all the loaded assemblies (which was both unpred=
ictable and inefficient). There are three possible work around that I can t=
hink of:
1) This may or may not work, depending on what the context class loader is,=
but you can statically link saxon8sa.dll to Transform.exe, that way it bec=
omes part of the class loader graph of Transform.exe and when the system cl=
ass loader is used (which will be the assembly class loader associated with=
the application's main executable), it should be able to find the class (b=
ecause an assembly class loader searches the corresponding assembly and all=
assemblies it *directly* references).
(Note that the C# compiler does not actually add an assembly reference if y=
ou use /r but don't use any type in the assembly, so you must add some code=
that actually touches a type in the assembly.)
2) Write a custom class loader that knows how to load com.saxonica.validate=
.SchemaAwareConfiguration and use Thread.setContextClassLoader to set it.
3) Use Class.forName() with an assembly qualified name.
I hope this helps.
Regards,
Jeroen
|