[Mono-list] Assembly.LoadFrom() - Assembly.CreateInstance() - Activator.CreateInstanceFrom() ---> invalid cast
Jaroslaw Kowalski
jaak@zd.com.pl
Mon, 26 Jan 2004 17:12:33 +0100
> > Type t = Type.GetType("System.Data.SqlClient.SqlConnection, System.Data,
> > Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
> I think it's way better to use something like:
> Assembly a = Assembly.LoadWithPartialName ("System.Data");
> Type t = a.GetType ("System.Data.SqlClient.SqlConnection");
> ...
> because I guess your code is going to break with the next (or different
> versions) of the CLR where the exact same version may not be available.
>
Actually this string is usually stored in a configuration file so there is
no problem for me.
BTW. .NET 1.1 supports a transparent assembly redirection for system
assemblies. i.e. when you ask for
Type.GetType("System.Data.SqlClient.SqlConnection, System.Data,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
you're gonna get the same thing as.
Type.GetType("System.Data.SqlClient.SqlConnection, System.Data,
Version=1.1.4322, Culture=neutral, PublicKeyToken=b77a5c561934e089")
instead because MS "knows" this latter type is backwards compatible (this
applies to all assemblies located in Microsoft.NET\Framework\v1.1.4322) .
This is a new behaviour introduced in .NET 1.1 to eliminate unneccessary
assembly redirections.
Note that .NET 1.0 behaves differently here (it will let you two
System.Data's from two CLR versions provided that they are in the GAC)
Does mono support this?
Jarek