473,503 Members | 2,139 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(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(
a.GetType("System.Data.OleDb.OleDbConnection"),
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.InvalidCastException: 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.IDbConnection'

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

Thanks for your help!

Dave Eland
da******@oru.edu
Nov 16 '05 #1
2 2127
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
993
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...
3
4697
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...
5
5005
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...
2
2351
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...
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
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...
1
3202
by: Gujju | last post by:
Hi all, Whats the difference betwn Assembly.Load(FileName) and Assembly.LoadFrom(FileName.dll) ? Cheers C
6
44471
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 =...
12
1684
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...
0
7204
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
7091
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
7282
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
7342
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
7464
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
5586
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,...
0
4680
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...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1516
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 ...

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.