AW: [Mono-list] Assembly.LoadFrom() - Assembly.CreateInstance()
- Activator.CreateInstanceFrom() ---> invalid cast
Timothy Parez
tpsoftware@users.sourceforge.net
Tue, 27 Jan 2004 09:09:32 +0100
This is a multi-part message in MIME format.
--------------010109040604040307060902
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Christian Birkl wrote:
>Hi,
>
>
>
>>Stating it is an invalid cast.
>>
>>
>
>Can someone please explain me the following behaviour:
>
> Assuming you have Assembly "A.dll", with one class Y (no
>methods, no fields, just a plain class). Now copy this assembly to
>A.1.dll, A.2.dll. You now have 3 assembly, A.dll, A.1.dll, A.2.dll (they
>just differ in date of last modification).
>
>Create a new project which references "A.dll" and write the following
>main function:
>
> static void Main(string[] args)
> {
> Type t1 = Assembly.LoadFrom(@"A.1.dll").GetType("A.Y");
> Type t2 = Assembly.LoadFrom(@"A.2.dll").GetType("A.Y");
> Type t3 = typeof(A.Y);
>
> Console.WriteLine(t1.GUID);
> Console.WriteLine(t2.GUID);
> Console.WriteLine(t3.GUID);
>
> Console.WriteLine(t1 == t2);
> Console.WriteLine(t1 == t3);
> Console.WriteLine(t2 == t3);
> }
>
>Now guess the output (MS.NET 1.1 runtime):
>
>d899aa25-2426-3ef7-91c2-95e6f8aaed27
>d899aa25-2426-3ef7-91c2-95e6f8aaed27
>d899aa25-2426-3ef7-91c2-95e6f8aaed27
>True
>False
>False
>
>Hu? :-). Why is t1 != t3, but t1 equals t2? Anyone?
>
>So i guess that's related to your problem with your MySQL.ByteFX
>DataProvider. You load your ByteFX assembly via Assembly.LoadFrom, which
>references System.Data in its own "dll" scope. Your program also
>references "System.Data", but somehow the "System.Data" of your program
>isn't the same as in your lazy loaded ByteFX assembly.
>
>I can't give you a solution for this, but if your application is a web
>app i think you run into the problems if you're not using XSP but IIS
>since IIS copies all bin\* files into some temporary directories and
>there you'll get the same behaviour as stated above. (IIS does this in
>order to enable dynamic reloading of web apps. Ever tried to update one
>dll in your C:\inetpub\wwwroot\<App\bin\ directory? It is not locked,
>you can overwrite it and if you do it, IIS will implicitly redeploy your
>web app to reflect the update - makes life much easier 8-))
>
>Christian
>
>_______________________________________________
>Mono-list maillist - Mono-list@lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/mono-list
>
>
>
Hmm, what if I load System.Data.dll aswell ?
--------------010109040604040307060902
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body>
Christian Birkl wrote:<br>
<blockquote cite="mid000a01c3e462$28680720$0200a8c0@winghome"
type="cite">
<pre wrap="">Hi,
</pre>
<blockquote type="cite">
<pre wrap="">Stating it is an invalid cast.
</pre>
</blockquote>
<pre wrap=""><!---->
Can someone please explain me the following behaviour:
Assuming you have Assembly "A.dll", with one class Y (no
methods, no fields, just a plain class). Now copy this assembly to
A.1.dll, A.2.dll. You now have 3 assembly, A.dll, A.1.dll, A.2.dll (they
just differ in date of last modification).
Create a new project which references "A.dll" and write the following
main function:
static void Main(string[] args)
{
Type t1 = Assembly.LoadFrom(@"A.1.dll").GetType("A.Y");
Type t2 = Assembly.LoadFrom(@"A.2.dll").GetType("A.Y");
Type t3 = typeof(A.Y);
Console.WriteLine(t1.GUID);
Console.WriteLine(t2.GUID);
Console.WriteLine(t3.GUID);
Console.WriteLine(t1 == t2);
Console.WriteLine(t1 == t3);
Console.WriteLine(t2 == t3);
}
Now guess the output (MS.NET 1.1 runtime):
d899aa25-2426-3ef7-91c2-95e6f8aaed27
d899aa25-2426-3ef7-91c2-95e6f8aaed27
d899aa25-2426-3ef7-91c2-95e6f8aaed27
True
False
False
Hu? :-). Why is t1 != t3, but t1 equals t2? Anyone?
So i guess that's related to your problem with your MySQL.ByteFX
DataProvider. You load your ByteFX assembly via Assembly.LoadFrom, which
references System.Data in its own "dll" scope. Your program also
references "System.Data", but somehow the "System.Data" of your program
isn't the same as in your lazy loaded ByteFX assembly.
I can't give you a solution for this, but if your application is a web
app i think you run into the problems if you're not using XSP but IIS
since IIS copies all bin\* files into some temporary directories and
there you'll get the same behaviour as stated above. (IIS does this in
order to enable dynamic reloading of web apps. Ever tried to update one
dll in your C:\inetpub\wwwroot\<App\bin\ directory? It is not locked,
you can overwrite it and if you do it, IIS will implicitly redeploy your
web app to reflect the update - makes life much easier 8-))
Christian
_______________________________________________
Mono-list maillist - <a class="moz-txt-link-abbreviated" href="mailto:Mono-list@lists.ximian.com">Mono-list@lists.ximian.com</a>
<a class="moz-txt-link-freetext" href="http://lists.ximian.com/mailman/listinfo/mono-list">http://lists.ximian.com/mailman/listinfo/mono-list</a>
</pre>
</blockquote>
Hmm, what if I load System.Data.dll aswell ?<br>
<br>
</body>
</html>
--------------010109040604040307060902--