Controlling .NET App Domains

Parent Previous Next

.NET application domains are a CLR (Common Language Runtime) feature that can be likened to lightweight processes within a managed process.  Assemblies are loaded into and types are created in a particular AppDomain.  Why is this important?  Static objects are scoped by AppDomain.  In addition, an AppDomain may be configured by a specific .NET configuration XML file.


Intuitively, one would guess that each BizTalk application is isolated from every other application.  This, unfortunately, is not the case.  By default, BizTalk loads and executes assemblies from many BizTalk applications in a single AppDomain.  As a result, if your code uses a static/singleton object that is implemented in a common assembly, each running application will share the same static/singleton object state.  This may lead to unanticipated data sharing or conflicts between BizTalk apps.


To avoid this problem, BizTalk can be configured to run a particular set of assemblies in a distinct AppDomain to provide true isolation from other BizTalk applications.  Each AppDomain will have a distinct instance of shared static/singleton objects.  Alternatively, the application might require configuration data from an XML configuration file, like that of Microsoft Enterprise Library.  A separate AppDomain can be configured to use a specific application-defined XML configuration file path.


These settings are stored in the BizTalk BTSNTSvc.exe.config file.  The Framework can automatically update the configuration file while deploying and undeploying the application.


To instruct BizTalk to run your application in an isolated AppDomain, edit your Deployment Framework for BizTalk project file (.btdfproj) as follows:


Set the UseIsolatedAppDomain property to true

The property may be included in any PropertyGroup, but is commonly placed in the first PropertyGroup in the project file.


<PropertyGroup>

 ...

 <UseIsolatedAppDomain>true</UseIsolatedAppDomain>

 ...

</PropertyGroup>


This feature utilizes a custom MSBuild task called UpdateBizTalkAppDomainConfig, which can also be used to specify a configuration file path and other options.


Created with the Personal Edition of HelpNDoc: Create iPhone web-based documentation