473,583 Members | 2,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem in Load vs LoadFrom

The following fragment of code exhibits some anomolous behavior:

public IDbConnection GetConnection(s tring cnstr)
{
1 IDbConnection cn = null;
2 Assembly a = Assembly.Load(" System.Data");
3 Assembly a = Assembly.LoadFr om("System.Data .dll");
4 cn = (IDbConnection) Activator.Creat eInstance(
a.GetType("Syst em.Data.OleDb.O leDbConnection" ),
new Object[]{cnstr});
return (cn);
}

When using the code in line 2, everything works OK.
When using the code in line 3, the following error occurs at line 4:

Unhandled Exception: System.InvalidC astException: Specified cast is
not valid

If you try to leave out the cast on line 4, you get a compile time
error:

Cannot implicitly convert type 'object' to 'System.Data.ID bConnection'

Why would the use of "Load" result in a different behavior from using
"LoadFrom"?

Thanks for your help!

Dave Eland
da******@oru.ed u
Nov 16 '05 #1
2 2133
Why would the use of "Load" result in a different behavior from using
"LoadFrom"?


See http://www.gotdotnet.com/team/clr/Lo...Isolation.aspx

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
Thank you. That explains it!

Dave Eland
-----Original Message-----
Why would the use of "Load" result in a different behavior from using"LoadFrom"?
See

http://www.gotdotnet.com/team/clr/Lo...Isolation.aspx
Mattias

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

Nov 16 '05 #3

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

Similar topics

0
999
by: Xedecimal | last post by:
I've been playing around with assemblies and I've run into quite the little issue. if you load your .dll up into a byte array, and your .pdb into another byte array, then use Assembly.Load(array1, array2); It will load fine, but if this file you're loading into byte arrays, loads up another dll in the same manner, that is manually...
3
4700
by: Mike Krueger | last post by:
Hi I'm currently working on a forms designer for a free .NET IDE (SharpDevelop -> www.icsharpcode.net/OpenSource/SD). problem: I try to put 'custom' components (user controls from the current open project) into the forms designer. The project must be compiled for making this work. Now after recompile I need to update the user control...
5
5013
by: Lucas | last post by:
Well, here's the situation.. It's pretty simple; just that I can't get it to work. I have 2 Executables.. The first one is called CSharp.exe which is a simple WinForm App. I have a single button on the form which does the following OnClick. // CSharp.cs private void button1_Click(object sender, System.EventArgs e)
2
2358
by: Bülent Üstün | last post by:
Hi, i've a DLL file which contains a class i wrote named up2date (its not windows.forms). Which contains a constructor public up2date(string url,string domain) Now i want to load this DLL & use that class. I load the assembly with Assembly i = Assembly.LoadFrom( "update.dll" ); When i used
0
316
by: Dave Eland | last post by:
The following fragment of code exhibits some anomolous behavior: public IDbConnection GetConnection(string cnstr) { 1 IDbConnection cn = null; 2 Assembly a = Assembly.Load("System.Data"); 3 Assembly a = Assembly.LoadFrom("System.Data.dll"); 4 cn = (IDbConnection) Activator.CreateInstance(...
3
269
by: Alexander Brown | last post by:
I run the following code: Control control = pluginInstance.Control; Console.WriteLine("type is "+control.GetType()); NewControl castControl = (NewControl)control; The Console has "type is MyNamespace.NewControl" written to it. However the third line of code throws a "Specified case is not valid exception". Can anyone tell me why this...
1
3207
by: Gujju | last post by:
Hi all, Whats the difference betwn Assembly.Load(FileName) and Assembly.LoadFrom(FileName.dll) ? Cheers C
6
44475
by: Steve | last post by:
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\TestModule\bin\Debug\TestModule"; Assembly a = Assembly.Load(modulePath); </code>
12
1703
by: Ron M. Newman | last post by:
Hi, I can load an assembly using the Assembly.Load(....) However, I'd like dynamic loading of assemblies to be identical to putting an assembly reference in your VS2005 project. and yes, I know about the unloading problems. Let's say I don't care for the moment. If I have an assemlbly file at "c:\\assembly.dll" - how do I load it at...
0
8159
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8314
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7922
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8185
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6571
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5689
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1416
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.