By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,186 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

Problems loading an assembly

P: n/a
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().Full Name);

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
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"Aashish Patil" wrote:
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().Full Name);

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

Nov 16 '05 #2

P: n/a
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.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Alexander Wehrli" <Al*************@discussions.microsoft.com> wrote in
message news:E4**********************************@microsof t.com...
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

"Aashish Patil" wrote:
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().Full Name);

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


Nov 16 '05 #3

P: n/a
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4

P: n/a
I'd then recommend that you use the Assembly.LoadFromFile method.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

"Aashish Patil" <an**********@nospam.net> wrote in message
news:Od**************@TK2MSFTNGP15.phx.gbl...
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.