Problems loading an assembly

  • Thread starter Thread starter Aashish Patil
  • Start date Start date
A

Aashish Patil

Hi,

My code is trying to load an assembly using

Assembly.Load(string assemblyName);

Assume that the current executing assembly is called
Test.dll

The following code works fine
string assName = "Test.dll"
Assembly.Load(assName);

While the following fails consistently
Assembly.Load(Assembly.GetExecutingAssembly().FullName);

The second piece of code always throws an exception saying
that assembly was not found. Note that FullName also
includes attributes such as Culture,Version, ... I wonder
why that should make a difference.

Any ideas?

Thanks
regards,
Aashish
 
Hi,

This is because the FullName gives you a string like this:
trlcxml, Version=1.0.1705.13332, Culture=neutral, PublicKeyToken=null

So this isn't really the name of your assembly =D

What you can do is take the first part of the string (in my case trlcxml)
--> this is the name of your dll (without extension). Or (what I actually
prefer), you create an own class that contains either the assembly AND for
example a FileInfo Object of your assembly.

Regards kahuna
 
Gents,

According to MSDN, the Load method of the Assembly class SHOULD accept the
long form of the assembly name. To quote the MSDN topic:

<Quote>
Assembly SampleAssembly;
// You must supply a valid fully qualified assembly name here.
SampleAssembly = Assembly.Load("Assembly text name, Version, Culture,
PublicKeyToken");
</Quote>

The original poster should use the Fusion Log Viewer (fuslogvw.exe) utility
to examine which locations the loader probes for the assembly - the thing
might be the loader is not aware of the location where the assembly in
question resides.
 
Hi,

Apparently, the Assembly.Load method needs the 'filename' of the
assembly and not the actually assembly name. The docs for this methods
seemed a bit misleading. Anyway, got it to work by using

string codeBase = Assembly.GetExecutingAssembly().CodeBase
string filename = Path.GetFileName(codeBase);

Thanks for your help.

Regards,
Aashish
 
I'd then recommend that you use the Assembly.LoadFromFile method.
 
Back
Top