473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1808
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Elliott | last post by:
I am trying to load an assembly and execute a method from a class. I have listed 3 parts to the code. 1) The Driver to load and execute 2) The Interface 3) The assembly I have a valid referece...
2
by: Simon X-Session | last post by:
Hi ! I hope somebody can help me, i'm completly out of mind. My problem: I have a class inherited from Windows.Forms.Control named BasicModule, which implements an interface named IModule...
2
by: Foehammer | last post by:
Hello, I'm trying to load an assembly dynamically using an app domain. This is a proof-of-concept for a larger project, so please excuse the lame class names. TestLib is the dll where all the...
1
by: John Wright | last post by:
I justed loaded BETA 2 and it cause quite a few problems. Every time I try to view the designer I get the following error: Could not load type...
4
by: Mark | last post by:
I wan't to be able to deserialize a class from an assembly that is not in the application domain. To do that I must have the Type from the Assembly. How do you get a Type from an assembly that is...
9
by: Ender | last post by:
I have an application that I would like third party developers to be able to create Plug-ins that will be dynamically loaded into our application to extend functionality. I have utilized the...
2
by: Razzie | last post by:
Hey all, I'm working on this project where I'm dynamically loading an assembly. Basically what I want is that I can just replace my old dll file with a new one without having to do anything...
1
by: John F | last post by:
Hello all, When dynamically loading classes through reflection using Assembly.LoadFrom I have the following questions: 1) Once you load an assembly it doesn't appear you can unload it. If you...
5
by: Mantorok | last post by:
Hi I have a project that references one of our components, is there a way in ..Net to get a list of references that the application is depending on? The reason for this is so I can load...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.