473,385 Members | 1,753 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,385 software developers and data experts.

Assembly.Load() exception

I'm playing with late binding and trying a very simple test to load an
assembly

In my "Host" application I have this code:
<code>
string modulePath =
@"C:\PMDRepository\Tools\ManfBusProcMgr\Modules\Te stModule\bin\Debug\TestModule";
Assembly a = Assembly.Load(modulePath);
</code>

This is throwing the following exception:
Could not load file or assembly
'C:\\PMDRepository\\Tools\\ManfBusProcMgr\\Modules \\TestModule\\bin\\Debug\\TestModule'
or one of its dependencies. The given assembly name or codebase was invalid.
(Exception from HRESULT: 0x80131047)
The assembly that I'm trying to load is just a simple class library with one
member and one property. Both were created in VS2005.
I've done some initial googling, but nothing is popping up. Any ideas?

Thanks for reading!
Steve Klett
Jan 24 '06 #1
6 44451
><code>
string modulePath =
@"C:\PMDRepository\Tools\ManfBusProcMgr\Modules\T estModule\bin\Debug\TestModule";
Assembly a = Assembly.Load(modulePath);
</code>


Assembly.Load takes a assembly name, not a file path. You can try
Assebmly.LoadFrom instead (though it has its own set of problems).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 24 '06 #2
I tried just the name and I get the same exception.
Does the assembly need to be in the same location as the loading assembly?
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:ep**************@TK2MSFTNGP10.phx.gbl...
<code>
string modulePath =
@"C:\PMDRepository\Tools\ManfBusProcMgr\Modules\ TestModule\bin\Debug\TestModule";
Assembly a = Assembly.Load(modulePath);
</code>


Assembly.Load takes a assembly name, not a file path. You can try
Assebmly.LoadFrom instead (though it has its own set of problems).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jan 24 '06 #3
You did not specify the filename or you forgot to put the extention on the
filename.

TestModule needs to have an extention (.DLL or .EXE).

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Charles Cox
VC/VB/C# Developer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"Steve" <ss*@sss.com> wrote in message
news:ex**************@TK2MSFTNGP09.phx.gbl...
I'm playing with late binding and trying a very simple test to load an
assembly

In my "Host" application I have this code:
<code>
string modulePath =
@"C:\PMDRepository\Tools\ManfBusProcMgr\Modules\Te stModule\bin\Debug\TestModule";
Assembly a = Assembly.Load(modulePath);
</code>

This is throwing the following exception:
Could not load file or assembly
'C:\\PMDRepository\\Tools\\ManfBusProcMgr\\Modules \\TestModule\\bin\\Debug\\TestModule'
or one of its dependencies. The given assembly name or codebase was
invalid. (Exception from HRESULT: 0x80131047)
The assembly that I'm trying to load is just a simple class library with
one member and one property. Both were created in VS2005.
I've done some initial googling, but nothing is popping up. Any ideas?

Thanks for reading!
Steve Klett

Jan 24 '06 #4
That's the confusing part. LoadFrom() works when I specify the full path to
the module including extension. But Load() just wants the modul name, which
in my case is TestModule, but it failes.

Either way, LoadFrom() is working and that's fine for me, at least for
testing at this point.

Thanks for the post!

"C.C. (aka Me)" <me@home.com> wrote in message
news:7u********************@comcast.com...
You did not specify the filename or you forgot to put the extention on the
filename.

TestModule needs to have an extention (.DLL or .EXE).

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Charles Cox
VC/VB/C# Developer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"Steve" <ss*@sss.com> wrote in message
news:ex**************@TK2MSFTNGP09.phx.gbl...
I'm playing with late binding and trying a very simple test to load an
assembly

In my "Host" application I have this code:
<code>
string modulePath =
@"C:\PMDRepository\Tools\ManfBusProcMgr\Modules\Te stModule\bin\Debug\TestModule";
Assembly a = Assembly.Load(modulePath);
</code>

This is throwing the following exception:
Could not load file or assembly
'C:\\PMDRepository\\Tools\\ManfBusProcMgr\\Modules \\TestModule\\bin\\Debug\\TestModule'
or one of its dependencies. The given assembly name or codebase was
invalid. (Exception from HRESULT: 0x80131047)
The assembly that I'm trying to load is just a simple class library with
one member and one property. Both were created in VS2005.
I've done some initial googling, but nothing is popping up. Any ideas?

Thanks for reading!
Steve Klett


Jan 24 '06 #5
But the two methods are not the same.. See below from the MSDN
documentation:

Assembly SampleAssembly;
// You must supply a valid fully qualified assembly name here.
SampleAssembly = Assembly.Load("Assembly text name, Version,
Culture, PublicKeyToken");
Type[] Types = SampleAssembly.GetTypes();
// Display all the types contained in the specified assembly.
foreach (Type oType in Types)
{
Console.WriteLine(oType.Name.ToString());
}
Load takes a fully qualified assembly name, not the name of a file.

Hope this helps.

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Charles Cox
VC/VB/C# Developer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"Steve" <ss*@sss.com> wrote in message
news:OV**************@TK2MSFTNGP12.phx.gbl...
That's the confusing part. LoadFrom() works when I specify the full path
to the module including extension. But Load() just wants the modul name,
which in my case is TestModule, but it failes.

Either way, LoadFrom() is working and that's fine for me, at least for
testing at this point.

Thanks for the post!

"C.C. (aka Me)" <me@home.com> wrote in message
news:7u********************@comcast.com...
You did not specify the filename or you forgot to put the extention on
the filename.

TestModule needs to have an extention (.DLL or .EXE).

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Charles Cox
VC/VB/C# Developer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"Steve" <ss*@sss.com> wrote in message
news:ex**************@TK2MSFTNGP09.phx.gbl...
I'm playing with late binding and trying a very simple test to load an
assembly

In my "Host" application I have this code:
<code>
string modulePath =
@"C:\PMDRepository\Tools\ManfBusProcMgr\Modules\Te stModule\bin\Debug\TestModule";
Assembly a = Assembly.Load(modulePath);
</code>

This is throwing the following exception:
Could not load file or assembly
'C:\\PMDRepository\\Tools\\ManfBusProcMgr\\Modules \\TestModule\\bin\\Debug\\TestModule'
or one of its dependencies. The given assembly name or codebase was
invalid. (Exception from HRESULT: 0x80131047)
The assembly that I'm trying to load is just a simple class library with
one member and one property. Both were created in VS2005.
I've done some initial googling, but nothing is popping up. Any ideas?

Thanks for reading!
Steve Klett



Jan 24 '06 #6
Assembly.Load requires the full name, also known as the display name, of the
assembly, which is either its simple name (e.g. MyAssembly) without an
extension, or the fully qualified name, which consists of its simple name, a
version, a public key token, and its culture. For example,
Assembly.Load( "MyAsm, Version=1.0.1.220, Culture=Neutral,
PublicKeyToken=83b26e4166b7e1b8");

This also requires that the assembly be located either in the appdomain's
base directory, in a directory below there and which is one of the
components of the appdomain's PrivateBinPath, (so that the runtime knows how
to locate it), or specified in an app.config with a binding redirect and a
codebase hint. There are other places it can be located and mechanisms used
to tell the runtime how to find it, but these ought to get you started.
There are lots of options.

If you use Assembly.LoadFrom the the argument specified if the fully
specified path, either on the file system or to a url. This does not require
that the assembly be located in your appdomain's base directory, but it has
other limitations that can cause problems. Another major difference is that
the runtime internally stores loaded assemblies into multiple lists; the
Load context and the LoadFrom context (and others).

I've found it is usually better to use Load rather then LoadFrom because of
the way that the runtime locates and loads dependencies. If you use LoadFrom
you'll usually find it necessary to also subscribe to the
AppDomain.AssemblyResolve event to manually load dependencies of that
assembly.

I prefer to use a combination approach. I use:

AssemblyName an = AssemblyName.GetAssemblyName(filePath);
Assembly.Load(an);

This loads the filepath into the AssemlyName's codebase field and also
extracts all the other information from the assembly's manifest (version,
token, and culture). When you call Assembly.Load(an) the runtime tries to
load the assembly using the display name information, and if it can resolve
it it loads it into the Load context. If that fails it falls back to doing a
LoadFrom on the file path, loading it into the LoadFrom context.

Dave
"Steve" <ss*@sss.com> wrote in message
news:ex**************@TK2MSFTNGP09.phx.gbl...
I'm playing with late binding and trying a very simple test to load an
assembly

In my "Host" application I have this code:
<code>
string modulePath =
@"C:\PMDRepository\Tools\ManfBusProcMgr\Modules\Te stModule\bin\Debug\TestModule";
Assembly a = Assembly.Load(modulePath);
</code>

This is throwing the following exception:
Could not load file or assembly
'C:\\PMDRepository\\Tools\\ManfBusProcMgr\\Modules \\TestModule\\bin\\Debug\\TestModule'
or one of its dependencies. The given assembly name or codebase was
invalid. (Exception from HRESULT: 0x80131047)
The assembly that I'm trying to load is just a simple class library with
one member and one property. Both were created in VS2005.
I've done some initial googling, but nothing is popping up. Any ideas?

Thanks for reading!
Steve Klett

Jan 24 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kumaran via .NET 247 | last post by:
I'm building a Shared Addin for Outlook using C#. I'm using latebinding to determine the version ofoutlook installed on a machine, and load the addin instance forthat particular version of...
2
by: Lauren Hines | last post by:
Hello, I have read numerous post stating that the only way to unload an assembly (DLL in my case) is to create a separate AppDomain, load the assembly, then unload it by calling AppDomain.Unload....
1
by: Greg Patrick | last post by:
My problem: I load an some assemblies (strong named) from a byte array using Assembly.Load(byte). They load fine. But one one of them is actually accessed, it's referenced assemblies can't be...
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...
0
by: Nadav | last post by:
Hi All, - I am working on a tool that manipulate managed assemblies, some of the functionality provided by the tool require manipulating the metadata sections of the managed assembly in a way it...
5
by: iamcs1983 | last post by:
Can I load a assembly from memory by Assembly.Load(string) ?
0
by: Reen | last post by:
Hi, I have a C++ project which I upgraded from Visual Studio.net 2003 to 2005. I am compiling it using /clr:oldSyntax. When I try to load this dll in a C# application (in 2005) using...
4
by: Brian Richards | last post by:
Is it possible to run code in an assembly when it's loaded? In my case I have an assembly that requires that the users path be setup correctly or GetTypes() will throw an exception. Looking for a...
1
by: Adam Right | last post by:
Hi, I use Assembly.LoadFrom to load my assembly which is the user interface dll for my application. After loading, i invoke the entry method to run my application. But when the application...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.