views:

302

answers:

1

How to load an assembly into different AppDomain on Windows Mobile (.NET CF) for subsequent AppDomain unload ?

A: 

Try something like this:

class ServiceApplicationProxy : MarshalByRefObject
{
    public void Configure()
    {
        Assembly serviceAssembly = Assembly.Load(new AssemblyName()
        {
            CodeBase = @"c:\fullpath\assembly.dll")
        });
        // do something
    }
}

class Class1
{
    public void Start()
    {
        Type activator = typeof(ServiceApplicationProxy);
        AppDomain domain = AppDomain.CreateDomain(
            "friendlyName", null, new AppDomainSetup());
        ServiceApplicationProxy proxy =
            domain.CreateInstanceAndUnwrap(
                Assembly.GetAssembly(activator).FullName,
                activator.ToString()) as ServiceApplicationProxy;

        Console.WriteLine("Press ENTER to exit");
        Console.ReadLine();
        AppDomain.Unload(domain);
    }
}

EDIT: From documentation at http://msdn.microsoft.com/en-us/library/system.appdomain(VS.71).aspx:

.NET Compact Framework Platform Note: The .NET Compact Framework does not support loading assemblies into a domain neutral code area for use by multiple application domains.

Rubens Farias
Hi Rubens, I appreciate your efforts to answer my question.However CreateInstanceAndUnwrap method is not available on .NET Compact Framework.
kriau
Sorry, when I saw `AppDomain` available on CF, I assumed all type methods would be also available
Rubens Farias