Strong-named assembly calling unsigned assembly: FileNotFoundexception

C

Carol

I have a strong-name assembly, says AssemblyA.dll, and I also have a
unsigned assembly, says AssemblyB.dll. And the AssemblyB.dll refers to
another unsigned assembly AssemblyC.dll.

For some reasons, I have to keep AssemblyA signed, and I cannot sign
AssemblyB and AssemblyC.
I used P\Invoke in AssemblyA to call the method of AssemblyB. Every
thing works fine when the method in AssemblyB doesn't refer to any
other dll.

But the FileNotFound exception of {"Could not load file or assembly '
AssemblyC, Version=1.0.33.0, Culture=neutral, PublicKeyToken=null' or
one of its dependencies. The system cannot find the file
specified.":"AssemblyC, Version=1.0.33.0, Culture=neutral,
PublicKeyToken=null"} is thrown when the method calls the
AssemblyC ...

Any ideas / solutions ?? Thanks.
 
P

Pavel Minaev

I have a strong-name assembly, says AssemblyA.dll, and I also have a
unsigned assembly, says AssemblyB.dll. And the AssemblyB.dll refers to
another unsigned assembly AssemblyC.dll.

For some reasons, I have to keep AssemblyA signed, and I cannot sign
AssemblyB and AssemblyC.
I used P\Invoke in AssemblyA to call the method of AssemblyB.  Every
thing works fine when the method in AssemblyB doesn't refer to any
other dll.

Okay, stop right there. What do you mean by "use P/Invoke"? If
AsseblyB is indeed a .NET assembly, then you shouldn't need P/Invoke
(indeed, you wouldn't even be able to use it!). If it's not .NET, then
what is it? Just an unmanaged C++ DLL?

The same goes for AssemblyC. Also, explain the file layout of your
assemblies - i.e. where each is relative to others.
 
C

Carol

Thanks Pavel for reply.

All of the AsseblyA,B, C are .Net dlls

In AssemblyA, I have to use P/Invoke as I cannot refers to AssemblyB
directly
error CS1577: Assembly generation failed -- Referenced assembly
'AssemblyB' does not have a strong name

Is there any other way to call the method of AssemblyB?
 
F

Family Tree Mike

Carol said:
Thanks Pavel for reply.
All of the AsseblyA,B, C are .Net dlls

In AssemblyA, I have to use P/Invoke as I cannot refers to AssemblyB
directly
error CS1577: Assembly generation failed -- Referenced assembly
'AssemblyB' does not have a strong name

Is there any other way to call the method of AssemblyB?

As Pavel said, you cannot use P/Invoke. You must either fix your
constraints, as noted here (http://support.microsoft.com/kb/313666), or use
reflection.
 
C

Carol

Thank you, Mike

Actually I was using reflection, I guess I confused the Invoke()
method, I though that is the so-called P\Invoke, LOL

So actually my problem is with Invoke() method with reflection.
 
F

Family Tree Mike

Thank you, Mike

Actually I was using reflection, I guess I confused the Invoke()
method, I though that is the so-called P\Invoke, LOL

So actually my problem is with Invoke() method with reflection.


As Pavel said, you cannot use P/Invoke. You must either fix your
constraints, as noted here (http://support.microsoft.com/kb/313666), or
use
reflection.



So the reason you get an error in the first post is because you loaded
AssemblyB and used reflection to call a method on an object there, and
AssemblyB does not find a reference to AssemblyC. I believe that the way to
handle this is by calling Assembly.LoadFrom (a_path_to_AssemblyC).

The compiler error is because of mixing sign and unsigned. You should not
need a reference to AssemblyB in compiling AssemblyA if you use reflection.
 
C

Carol

Thank you, Mike!

You are absolutely right, it is the problem of the working path. I
have changed the

Environment.CurrentDirectory

to a location that has all the assemblies I need before

Assembly.LoadFrom()

and it works now :)

Actually this issue is not related with Strong-named assembly, I
should change the name of the thread if I could.
And a funny finding is: the default Environment.CurrentDirectory
pointers to "C:\WINDOWS\system32", that is the reason why it cannot
find the AssemblyC.
 
P

Pavel Minaev

Thank you, Mike!

You are absolutely right, it is the problem of the working path. I
have changed the

    Environment.CurrentDirectory

to a location that has all the assemblies I need before

    Assembly.LoadFrom()

and it works now :)

The point is that if you first load AssemblyC into your appdomain
using Assembly.LoadFrom() with full path, then, when you later load
AssemblyB, it should find AssemblyC already loaded, and just work.
Actually this issue is not related with Strong-named assembly, I
should change the name of the thread if I could.
And a funny finding is: the default Environment.CurrentDirectory
pointers to "C:\WINDOWS\system32", that is the reason why it cannot
find the AssemblyC.

Where was AssemblyC originally relative to the entry assembly
(the .exe with Main() method)? Normally, with default appdomain
settings, assemblies should be resolve relative to that (well, and GAC
of course). So if you just keep all your assemblies where your .exe
is, it should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top