[Mono-list] Assembly.Load doubts

2005-07-28 Thread Mario Sopena
I have the following scenario:

--  TestBase.cs ---
public interface TestBase {
void Print();
}


--Test.cs---
public class Test : TestBase 
{
public Test ()  {}
public void Print() 
{
System.Console.WriteLine (Hola);
}
}

--- TestClass.cs 
using System;
using System.Reflection;
public class TestClass 
{

public static void Main (string[] args) 
{
new TestClass();
}

public TestClass () 
{
AssemblyName asna = AssemblyName.GetAssemblyName (Test.dll);
Assembly asm = Assembly.LoadWithPartialName (asna.FullName);
Type t = asm.GetType(Test, true);
object obj = Activator.CreateInstance (t);
TestBase tb = (TestBase) obj;  //InvalidCastException
tb.Print();
}
}



I compile like this: 
mcs -target:library Test.cs TestBase.cs
mcs -debug TestClass.cs TestBase.cs

So I end up with a Test.dll and TestClass.exe. Now, executing the
TestClass.exe throws an InvalidCastException in the line with the
comment.

I think the problem is that i don't load the dll in the correct
context, but I've tried other possibilities and I couldn't make it
work. Two days ago I didn't know was an AppDomain was, so there is the
possibility that I'm doing something really stupid.

Any help pleaase?
___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] Assembly.Load doubts

2005-07-28 Thread Rodolfo Campero
Hi,

On 7/28/05, Mario Sopena [EMAIL PROTECTED] wrote:
 I have the following scenario:
 
 --  TestBase.cs ---
 public interface TestBase {
 void Print();
 }
 
 
 --Test.cs---
 public class Test : TestBase
 {
 public Test ()  {}
 public void Print()
 {
 System.Console.WriteLine (Hola);
 }
 }
 
 --- TestClass.cs 
 using System;
 using System.Reflection;
 public class TestClass
 {
 
 public static void Main (string[] args)
 {
 new TestClass();
 }
 
 public TestClass ()
 {
 AssemblyName asna = AssemblyName.GetAssemblyName (Test.dll);
 Assembly asm = Assembly.LoadWithPartialName (asna.FullName);
 Type t = asm.GetType(Test, true);
 object obj = Activator.CreateInstance (t);
 TestBase tb = (TestBase) obj;  //InvalidCastException
 tb.Print();
 }
 }
 
 
 
 I compile like this:
 mcs -target:library Test.cs TestBase.cs
 mcs -debug TestClass.cs TestBase.cs
 
 So I end up with a Test.dll and TestClass.exe. Now, executing the
 TestClass.exe throws an InvalidCastException in the line with the
 comment.
 
 I think the problem is that i don't load the dll in the correct
 context, but I've tried other possibilities and I couldn't make it
 work. Two days ago I didn't know was an AppDomain was, so there is the
 possibility that I'm doing something really stupid.
 
 Any help pleaase?

We just discussed this problem in monohispano:
https://listas.hispalinux.es/pipermail/mono-hispano/2005-July/003327.html
(I'm assuming that you speak spanish)

Cheers,
Rodolfo
___
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list