Calling from .Net 1.1 to .Net 2.0
Hi
A process cannot load both .net frameworks 1.1 & 2.0.
Therefore, to call 2.0 object from a 1.1 object, you must have a cross process call. One of the ways (but not the only) to do so, is to host the 2.0 object within COM+ process and expose it as a COM object. To do so, your object must derive Serviced Component and be marked as ComVisible.
Here is a simple example.
Save this as SimpleClient.cs
using System;
using System.Reflection;
public class SimpleClient
{
public static void Main()
{
Type t = Type.GetTypeFromProgID ("MyObject");
System.Diagnostics.Debug.Assert (t != null);
object o = Activator.CreateInstance(t);
Console.WriteLine (Environment.Version.ToString());
t.InvokeMember ("Increment", BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, o, new object[0]);
}
}
Save this as MyObject.cs
using System;
using System.Reflection;
using System.EnterpriseServices;
using System.Runtime.InteropServices;
[assembly: ApplicationActivationAttribute(ActivationOption.Server)]
[assembly: ApplicationName ("MyObject")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: ApplicationAccessControl(false)]
[System.Runtime.InteropServices.ComVisible (true)]
[Guid("65D66FCF-997E-4737-896D-60EEC0AF0E88")]
public class MyObject : ServicedComponent
{
public void Increment ()
{
System.Windows.Forms.MessageBox.Show("COM CALL - " + Environment.Version.ToString());
}
}
Create an snk file using the command "sn -k snk.snk"
Complie & register both source files with the following command lines:
"c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc" SimpleClient.cs
"c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc" /t:library MyObject.cs /keyfile:snk.snk
"c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regsvcs" MyObject.dll