[Mono-list] Assembly.LoadFrom() - Assembly.CreateInstance() - Activator.CreateInstanceFrom() ---> invalid cast

Paolo Molaro lupus@ximian.com
Mon, 26 Jan 2004 15:58:44 +0100

On 01/26/04 Jaroslaw Kowalski wrote:
> For MSSQL I do (watch for line breaks):
> Type t = Type.GetType("System.Data.SqlClient.SqlConnection, System.Data,
> Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
> IDbConnection conn = (IDbConnection)Activator.CreateInstance(t);
> Note, that Type.GetType() needs:
> 1. Local assembly name when the assembly is in application directory.
> 2. Fully qualified assembly name when the assembly is in the GAC or you want
> to take specific advantage of the assembly binding redirection.
> To get the fully qualified assembly name from GAC it's best to use: "gacutil
> /l"

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.


lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better