X++ in the BC.Net AppDomain and on the AOS

As I already wrote before, the BC.Net is an Ax-client and as an Ax-client able to execute X++-code. So your X++ method are by default executed within the calling AppDomain.

In order to identify the AppDomain in which the X++ is executed we write two methods (GetClientProcess and GetServerProcess) written in X++. The following schema shows where both methods will be executed:

Client Server X

The only difference between both methods is the keyword server which lets the code executing on the AOS and not on the Ax-client as done by default (you might explicitly precise this with the keyword “client”).

Method that should be executed by the BC.Net:

public static str  GetClientProcess()
System.AppDomain appDomain;
System.String appDomainName;
System.Diagnostics.Process process;
InteropPermission iop;
int pId;
str returnValue;
iop = new InteropPermission(InteropKind::ClrInterop);
appDomain = System.AppDomain::get_CurrentDomain();
process = System.Diagnostics.Process::GetCurrentProcess();
pId = process.get_Id();
appDomainName = appDomain.get_FriendlyName();
returnValue = appDomainName;
returnValue = returnValue + ‘ / ‘ + int2str(pId);

return returnValue;

Method that should be executed on the AOS:

public server static str  GetServerProcess()
//…same code as for the GetClientProcess-method

return returnValue;

Now execute the two methods with the following simple C# code:

static void Main(string[] args)
Microsoft.Dynamics.BusinessConnectorNet.Axapta ax;
string configuration = “C:\\Temp\\Sample.axc”;

ax = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();

ax.Logon(“DMO”, string.Empty, string.Empty, configuration);
Console.WriteLine(“Application did logon on the AOS”);

string clientProcessId = (string) ax.CallStaticClassMethod(“A01”, “GetClientProcess”);
string serverProcessId = (string) ax.CallStaticClassMethod(“A01”, “GetServerProcess”);

Console.WriteLine(“Client process: “ + clientProcessId);
Console.WriteLine(“Server process: “ + serverProcessId);
catch (Exception i)

Once you executed this application, you’ll see the following result:


You’ll find the process-Ids (PID) in task-explorer (I truncated the picture at the gray line a little bit in order to reduce the size of the picture):


This might seem natural and in I’ll agree on that, but you must always think about where you execute your code. This is especially very important to analyses errors and  performance issues.

Comments (0)