Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Error calling a C# dll from AX 2012

(3) ShareShare
ReportReport
Posted on by 82
Hi,
I am having a problem in AX 2012 when I use my dll. I create a dll in c# that calls a web service. The project is in .NET Framework 4.8 and the version of Newtonsoft.Json is 11.0.2. My packages.config has this: 
 
After I build the solution, I go to the project folder and, in the path bin/Debug, I copy the dll file. Later, I stop the AX service and paste that file in C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX_PRO\bin and then I start AX service again. When the service starts running, I create the reference in the AOT and then I make a cil to the project. When the cil is finish, I test the dll with a job. The problem is that when I try to use the dll, it shows this error:
 
Categories:
  • Vahid Ghafarpour Profile Picture
    9,720 Super User 2025 Season 1 on at
    Error calling a C# dll from AX 2012
    If any of the responses helped resolve your issue, please take a moment to mark the best answer. This helps others in the community quickly find solutions to similar problems.

    To do this, simply click the "Does this answer your question?" button on the most helpful response and like the helpful posts. If your issue is still unresolved, feel free to provide more details so the community can assist further!

    Thanks for being an active part of the Dynamics 365 Community! 😊
  • Martin Dráb Profile Picture
    233,013 Most Valuable Professional on at
    Error calling a C# dll from AX 2012
    I guess that "it stops running" means that an CRL exception was thrown and didn't handle it. Add a catch clause like this to see what the error is:
    catch (Exception::CLRError)
    {
        info(AifUtil::getClrErrorMessage());
    }
    Unfortunately, you haven't addressed the topic of the execution tier (client or server). Also, you didn't show us code used by the form.
     
    Both the job and the form run on client, but it says nothing about whether the class runs on client or server. The class or the method may be configured to run on server, even if it's called from client. Also, the form may be using some other code than the client. For example, let's say that the class is set up to run on the tier where it's called from, which is the client when called from the job, but your form may be calling a RunBase class to switch the execution to server.
     
    If you're not sure where the code executes, you can run it with the debugger and find this information there.
     
     
  • SP-22072258-0 Profile Picture
    82 on at
    Error calling a C# dll from AX 2012
    Hi,
    Ok. I will try yo explain it better:
     
    I have the class APIServices that has two methods: One to obtain the type of document (IM_CR_CreateElectronicInvoice) and the other one that uses a dll (IMCallWebApi). First, I call the method to obtain the document and then the one of the dll. The dll has the job to obtain all the data from the invoice and send it to a web service. This class is call when the user clicks on the button responsible to create the invoice.  When the user clicks the button, it calls another classes in order to create the invoice and then, by the end, calls the class APIServices. I have a job that calls that class with both methods and it works fine:
     
     
    But when I click the button it gets to the method IM_CR_CreateElectronicInvoice and inside this method I call the IMCallWebApi method but it does not runs. I verified it by adding some info messages, and it stops runnig in the line 84. It displays the info in line 81, but just that one:
     
     
     
     
  • Martin Dráb Profile Picture
    233,013 Most Valuable Professional on at
    Error calling a C# dll from AX 2012
    You said that it works when you execute a job from AOT but it doesn't work on client, but the job executes on client, doesn't it? Your statements seem to contradict each other. Please tell us more the job and the other scenario.
     
    Then tell us more about the problem than mere "it does not work". Also, I'm assuming you've already done some work on debugging, such as verified assuembly versions on client, used Assembly Binding Log Viewer or so. Please share these findings with us too.
     
  • SP-22072258-0 Profile Picture
    82 on at
    Error calling a C# dll from AX 2012
    Hi,
    I check the assembly and I solve part of the errors. First of all, I was copying the wrong dll (that was my bad). Then, what really solve part of my error was that in the folder of the Client, the Newtonsoft version was different from the one in the Server folder. 
     
    If I execute a job from the AOT that uses the dll it works perfectly, but when I do it from the client side it does not works. Does someone know what can be happening? 
  • Martin Dráb Profile Picture
    233,013 Most Valuable Professional on at
    Error calling a C# dll from AX 2012
    Your application seems to consists of three assemlies: CR_FaceIServices.dll, Json.dll and Newtonsoft.Json.dll. All are needed; AX can't load your CR_FaceIServices.dll if it can't find the other assumblies that yours depends on. I might find them at other probing paths, but if not, you need to add them to the bin folder(s).
     
    You seem to have Newtonsoft.Json.dll on AOS, but it's not clear whether you're executing code that runs there (or rather on the client).
     
    When you let AX deploy assemblies for you, it'll use %USERPROFILE%\AppData\Local\Microsoft\Dynamics AX\VSAssemblies, if I'm not mistaken. But you can also use the regular client bin folder: C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin.
     
    It's usually not needed, but if you run into problems with assembly loading that you can't figure out, there is a tool called Assembly Binding Log Viewer (Fuslogvw.exe) that will give you more details.
  • SP-22072258-0 Profile Picture
    82 on at
    Error calling a C# dll from AX 2012
    Hi Marting,
    Thank your for your answer. I'm kind of new in this dll topics. I will downgrade the .NET version and see if that works. Also, I will just like to understand more what are you telling me.
     
    When I said that I copy the dll, I copy the one from my c# project:
     
    When you say that it won't work if the system doesn't find the assembly with the requested version, how can I check the assembly? Because in my c# project it shows that the Newtonsoft version is the 11.0.2 and in AX it has the same version:
     
     
     
    As well, where is the client's folder? Because I only paste the dll in this location:
     
  • Suggested answer
    Martin Dráb Profile Picture
    233,013 Most Valuable Professional on at
    Error calling a C# dll from AX 2012
    As far as I know, AX 2012 doesn't support .NET Framework 4.8. The newest supported is 4.7, if your environment is on R3 CU12 or R2 CU9.
     
    Also, you mentioned copying "the DLL"; I'm assuming that you've copied just your assembly and not the referenced assembly, Newtonsoft.Json. It won't work if the system won't be able to find this assembly with the requested version somewhere else, e.g. in GAC. The error message says exactly that - it can't find Newtonsoft.Json, version 11.
     
    The third problem I see is that you didn't place the assembly/assemblies to the client folder, therefore compilation should fail, because it won't be able to find the necessary files. You would see that if you compiled your X++ code, but you didn't mention doing so. Generating CIL makes no effect if you don't compile X++, because it depends on output of the X++ compiler.
     
    Moved from Integration, Dataverse, and general topics forum to Finance | Project Operations, Human Resources, AX, GP, SL forum.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,013 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans