System.IO.FileNotFoundException: Could not load file or assembly

889 views
Skip to first unread message

Ashutosh

unread,
May 26, 2012, 12:55:59 PM5/26/12
to jni4net
Hi,

I have a requirement of printing letters as a background service.
these letters are MS Word document. Since my application is a java
application, i am not able to print letters by keeping word format
intact from java. I decided to write a .NET dll which will do this
task for me and planned to call this DLL using JNI4net (I am a java
developer and writing .net program first time). but when i generate
DLL and try to register this in my java program i am getting error. I
thought this is happening bcoz i am using office.dll and other MSword
dlll. but the same error message came when my .net program just has
console.writeline("haha"). Please help me because i already have
wasted lot of my time trying to print word doc from java.. Many
thanks....

Error message while registering DLL is :


System.IO.FileNotFoundException: Could not load file or assembly
'ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
or one of its dependencies. The system cannot find the file specified.
File name: 'ClassLibrary1, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'
at System.Reflection.CustomAttribute._CreateCaObject(Void* pModule,
Void* pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
at System.Reflection.CustomAttribute.CreateCaObject(Module module,
RuntimeMethodHandle ctor, IntPtr& blob, IntPtr blobEnd, Int32&
namedArgs)
at System.Reflection.CustomAttribute.GetCustomAttributes(Module
decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount,
RuntimeType attributeFilterType, Boolean mustBeInheritable, IList
derivedAttributes)
at
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType
type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Type attributeType,
Boolean inherit)
at net.sf.jni4net.utils.Registry.GetClrWrapperAttribute(Type type)
at net.sf.jni4net.utils.Registry.RegisterWrapper(Type wrapperType,
RegistryRecord& record)
at net.sf.jni4net.utils.Registry.RegisterType(Type type, Boolean
bindJVM, JNIEnv env, ClassLoader classLoader)
at net.sf.jni4net.utils.Registry.RegisterAssembly(Assembly
assembly, Boolean bindJVM, ClassLoader classLoader)
at net.sf.jni4net.Bridge.RegisterAssembly(Assembly assembly,
ClassLoader classLoader)
at
net.sf.jni4net.Bridge.LoadAndRegisterAssemblyFromClassLoader(File
assemblyFile, ClassLoader classLoader)
at net.sf.jni4net.Bridge.LoadAndRegisterAssemblyFrom(File
assemblyFile)
at net.sf.jni4net.__Bridge.LoadAndRegisterAssemblyFrom3(IntPtr
__envp, JniLocalHandle __class, JniLocalHandle assemblyFile)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM
\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind
failure logging.
To turn this feature off, remove the registry value [HKLM\Software
\Microsoft\Fusion!EnableLog].

Thanks
Ashu

Matej Gagyi

unread,
May 28, 2012, 8:01:58 AM5/28/12
to Ashutosh, jni...@googlegroups.com
Hi Ashutosh,

This happened to me too. If you load the library by relative name, keep in mind, that Java handles "current working directory" in a different way than most runtimes (in a property, I think the key is user.dir or similar). JVM process runs in $JAVA_HOME and CLR look for your relative paths from there!

Try to copy the DLLs to $JAVA_HOME first, or use absolute paths... you should be able to resolve absolute paths from inside Java. I wrote a CLR class, which changes the current directory for me. Keep messing with it.

I'd bed, you will encounter another problem after saving this. Some DLLs won't be found anyway, or will be corrupt. I don't know why this happens. I do this to solve it:
1. Bridge.init()
2. Load jni4net and all other depend

    public void initBootup() throws IOException {
        //Bridge.init(new File("c:\\Documents and Settings\\re56071\\Apps\\eclipse-36-j2se"));
        Bridge.init();
        Bridge.LoadAndRegisterAssemblyFrom(new File("deps/lib/jni4net.n-0.8.4.0.dll"));
        Bridge.LoadAndRegisterAssemblyFrom(new File("net/log4net.dll"));
        Bridge.LoadAndRegisterAssemblyFrom(new File("Util.dll"));
        Bridge.LoadAndRegisterAssemblyFrom(new File("Util.j4n.dll"));
    }

Hope, this helps.

Regards  / S pozdravomMatej Gagyi




Reply all
Reply to author
Forward
0 new messages