Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

RemotingConfiguration Unconfigure

2.63/5 (5 votes)
1 Sep 2008CPOL 1   151  
This article is about RemotingConfiguration and how to handle it.

Introduction

This article is about how to unconfigure after you have called RemotingConfiguration.Configure(<file.config>).

Background

I found a solution for RemotingConfiguration unconfigure which is quite simple after you understand what an AppDomain is. Read some tutorials (MSDN will be the best) on how to create an AppDomain.

Using the code

First, I create an AppDomain which I use in my project. For my purposes, I have:

C#
//Code
void Execute(string filepath, string filename)
{
    string exeAssembly = Assembly.GetExecutingAssembly().GetName().Name;
        AppDomainSetup ads = new AppDomainSetup();
        AppDomain ad2 = AppDomain.CreateDomain("NewDomain", null, ads);
        RemotingDomainObjects mbrt = (RemotingDomainObjects)ad2.CreateInstanceAndUnwrap(
                exeAssembly,
                typeof(RemotingDomainObjects).FullName);
        mbrt.DoConfiguration(filepath + filename, Session.SystemState);
        AppDomain.Unload(ad2);
}
//EndCode

Pay attention to RemotingDomainObjects and RemotingDomainObjects.DoConfiguration. Here I have:

C#
//Code
public class RemotingDomainObjects : MarshalByRefObject
    { 
        public void DoConfiguration(string str)
        {
            RemotingConfiguration.Configure(str);
            Customer obj = new Customer();
            Console.WriteLine("obj value = " + obj.get(108));
            Console.WriteLine("Press <Enter> to get the " + 
               "RemoteUnconfigure object or <Space> to exit!");
        }
    }
//EndCode

How it works

After AppDomain.Unload(ad2); is executed, all configurations on ad2 (AppDomain) are deleted. So you can configure over and over and there will be no problem. If you need additional information about my application, you can find me at hakkuss@yahoo.com.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)