Home > Ax Technical > Running a .Net reference code in the Server in Dynamics Ax

Running a .Net reference code in the Server in Dynamics Ax

February 8, 2011 Leave a comment Go to comments

We have been recently building some .Net solutions for our vertical. I have consolidated my learnings from it and publishing here as a post.

1. Adding a .Net reference can be as easy as just to drop the dll in the client bin folder and then add it. But if you want the code to execute on the server then this wont work. You will have to publish the dll in the server “GAC(Global Assembly Cache)”.  A assembly on the cache executes on the server.  Look here for articles on publishing a dll to the cache (GAC Publishing) and assigning strong name to it (Assigning Strong Key).

2. When you look at for the GACUtil, you will find it in different places in different pc. The general places to look at are,

-> C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin

-> C:\WINDOWS\Microsoft.NET\Framework\

3. Every time you change and build the solution you have to un publish/publish it to the GAC. This can be difficult to do it manually. The easiest way is to add the following lines in your Project -> Properties -> Post-build event command line  in your visual studio project.

//uninstal old version

“gacutil.exe -u $(TargetName)”

//register new version

“gacutil.exe -i $(TargetPath)”

4. Though you run the code on the GAC it is necessary that the dll is added to all the clients just for compilation. It need not be updated as you revise your dll.

5. If the code is present in a server call then it is required to restart the server every time you re publish a new version to the GAC.  What i found better was to test the code by client level execution(Through a job) and once the code is working fine you can move it to the server call.

6. If you are creating a .Net instance in a class and wanted to retain the instance as a global variable then you must declare the variable as CLRObject and not in the actual .Net namespace name(Eg: Microsoft.Dynamics.Csharp). Failing to do so results in a run time marshalling error.

Advertisements
  1. February 8, 2011 at 12:09 pm

    no you need not put it in the server/bin or client/bin. But if you are using it from some other client and want the code to compile in the client then you must drop it in the bin folder of the client.

  2. February 8, 2011 at 11:04 am

    Question, when you put the dll on the server, do you have to put it in the bin directory as well? I was not clear if I put in the GAC, do I have to put the dll in the server’s server/bin and/or/neither the server’s client/bin dir.
    Thanks… gary

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: