Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Running a .Net reference code in the Server in Dynamics AX 2009

Posted on by 5

We have an integration scenario, where we have done the following activities in mentioned sequence:

  1. Created a custom C# DLL (built using .NET Framework 3.5)
  2. Signed/strong-named using VS signing feature
  3. Registered/published the DLL in the server GAC using GACUtil.exe
  4. Placed the DLL in Server\Bin directory
  5. In Dynamics AX 2009, added the reference of the DLL (it appeared in the form without browsing in file explorer, as already registered in GAC)
  6. Restarted AOS services

We can see the DLL reference in the AX client (AOT -> Reference) installed on terminals.

Also, in the AOS, we can see the IntelliSense and code compiles without any error if we access some method in the referenced DLL.

Problem: AX client installed on terminals, is unable to read this DLL and throws a compilation error that the object does not exist.

Tried full compilation, RunOn Server property but the issue persists. Please guide.

P.S. Issue resolves if we place the DLL in Client\Bin directory but this is not an option as we have over 300 terminals and to place/update DLL in each of them is not a practical approach.

  • Bilal Saeed Profile Picture
    Bilal Saeed 5 on at
    RE: Running a .Net reference code in the Server in Dynamics AX 2009

    Thanks goshoom for the support. I was able to run my DLL-related code on the server after placing the DLL in the server's bin folder and without copying it in the client\bin directory.

  • Martin Dráb Profile Picture
    Martin Dráb 225,526 Super User on at
    RE: Running a .Net reference code in the Server in Dynamics AX 2009

    Are you sure that you now know how to run code on the server tier? Did you verify in debugger that it really runs on server?

  • Bilal Saeed Profile Picture
    Bilal Saeed 5 on at
    RE: Running a .Net reference code in the Server in Dynamics AX 2009

    So in my case, I want to run it on the server tier. So I placed it in: C:\Program Files\Microsoft Dynamics AX\50\Server\DAX2009\Bin

    But while adding a reference in AOT, it gives me the following message:

    pastedimage1656504184940v1.png

    I clicked yes, but AX is unable to load the assembly and gives me 'CLRObject not found' error.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 225,526 Super User on at
    RE: Running a .Net reference code in the Server in Dynamics AX 2009

    It depends. If you want to run the code on the server tier, you need to put your DLL to the (server) bin folder of your AOS server(s). Note that production environments usually have more than one AOS.

    If you want to run your code on the client tier and users run AX clients on several machines (not just from a single terminal server, for example), you need to install your DLL to the client bin folder on all those machines. Note that it can be automated, as discussed above.

  • Bilal Saeed Profile Picture
    Bilal Saeed 5 on at
    RE: Running a .Net reference code in the Server in Dynamics AX 2009

    Yes true. So in order to make it run on AOS and to be able to run my DLL methods from AX client on different machine, should I paste my DLL in following directory on AOS?

    C:\Program Files\Microsoft Dynamics AX\50\Server\DAX2009\Bin

    or C:\Program Files (x86)\Microsoft Dynamics AX\50\Client\Bin

  • Martin Dráb Profile Picture
    Martin Dráb 225,526 Super User on at
    RE: Running a .Net reference code in the Server in Dynamics AX 2009

    You installed your DLL to the AX client on that particular server. If you run an AX client from a different machine, the DLL doesn't exist on that machine at all and therefore it can't be loaded.

    I guess that you believe that your code is executed on AOS, not on AX client, but if it was true, it would have failed. You explicitly said that you installed the DLL just on AX client, not on the AOS, therefore your won't work on the server tier.

  • Bilal Saeed Profile Picture
    Bilal Saeed 5 on at
    RE: Running a .Net reference code in the Server in Dynamics AX 2009

    Hi goshoom

    Opening this thread again as the work was paused on this issue because of some problem. Now, I've resumed my work on it and still am unable to resolve the issue. Please note that now I'm following an approach where I'm running my code on server and have placed the DLL on the Client\Bin folder in batch server which is different from AOS.

    I have created a test job to check if my method in the DLL is being executed properly or not. The finding is that it runs well on the batch server where the DLL is placed, but not anywhere else. Error I receive is: "Object 'CLRObject' could not be created".

    Please guide that what am I missing. Code in the test job is pasted below.

    static server void IntConCheck(Args _args)
    {
        AxIntegration.Integration                       integrationClass;
        AxIntegration.ATPIntegrationRequestContract     req;
        ;
        
        new InteropPermission(InteropKind::CLRInterop).assert();
    
        integrationClass    = new AxIntegration.Integration();
        req                 = new AxIntegration.ATPIntegrationRequestContract();
        
        info(integrationClass.getATPValuesJSON(req));
    }

  • Bilal Saeed Profile Picture
    Bilal Saeed 5 on at
    RE: Running a .Net reference code in the Server in Dynamics AX 2009

    The DLL must be installed on all machines where you want to run it. You can either do it in GAC or by putting the DLL to a location where the process can find it, such as the bin folder.

    Okay, I get this.

    There is a way how to get files installed on clients (SysFileDeployment), but you didn't mention implementing it, therefore it's likely that haven't done it and that's why it doesn't work. Before implementing such a thing, are you sure that you must run the DLL on client and therefore it must be installed on all machines where you have AX clients? If you can run it on server, you don't need to worry about the installation on all clients.

    What I really want is to place DLL on server only, and run from there. But I was trying accessing it in code in dev terminal which was throwing error. What I understand from your comment is that, I should register DLL in the GAC or place it in bin folder in my dev terminals. And in other terminals the functionality should work without any issue if RunOn property is set to Server (even when DLL is not present in those terminals). Right?

    Thanks for letting me know about SysFileDeployment, it looks useful in case I need to copy DLLs to client Bin folder.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 225,526 Super User on at
    RE: Running a .Net reference code in the Server in Dynamics AX 2009

    The DLL must be installed on all machines where you want to run it. You can either do it in GAC or by putting the DLL to a location where the process can find it, such as the bin folder.

    There is a way how to get files installed on clients (SysFileDeployment), but you didn't mention implementing it, therefore it's likely that haven't done it and that's why it doesn't work. Before implementing such a thing, are you sure that you must run the DLL on client and therefore it must be installed on all machines where you have AX clients? If you can run it on server, you don't need to worry about the installation on all clients.

  • Bilal Saeed Profile Picture
    Bilal Saeed 5 on at
    RE: Running a .Net reference code in the Server in Dynamics AX 2009

    Thanks goshoom  for responding. I understand that if registered on GAC, I shouldn't be adding DLL to Bin folder, but does it mean that I'll need to register DLL in GAC in each terminal? I have read somewhere that in AX 2012, DLL is automatically copied from the VSAssemblies folder in AOS to the terminals/clients. Does no such thing exist in AX 2009?

    Start by asking yourself whether the DLL is really needed on client, or it could be used by AOSes only.

    Okay, let's say I use it only in AOS. But on compiling it on dev terminal it throws the error and my functionality breaks. Should I only be compiling it in AOS every time I make some change? And should it work well in that case? Unfortunately, I don't have access to my terminal right now due to some issues, so can't test before next week.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,835 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,526 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans