472,125 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,125 software developers and data experts.

Problems loading an assembly

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
4 1756
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
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
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
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.

Similar topics

2 posts views Thread by Simon X-Session | last post: by
1 post views Thread by John Wright | last post: by
2 posts views Thread by Razzie | last post: by
1 post views Thread by John F | last post: by
5 posts views Thread by Mantorok | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.