473,473 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Create 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 2124
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
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
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
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
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
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
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
by: Gujju | last post by:
Hi all, Whats the difference betwn Assembly.Load(FileName) and Assembly.LoadFrom(FileName.dll) ? Cheers C
6
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
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
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
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,...
1
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
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,...
1
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...
0
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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.