Philippsen's Blog

Everyday findings in my world of .net and related stuff

How to implement basic authentication in Dynamics AX2012 webservice

Posted by Torben M. Philippsen on February 26, 2016

Recently I had to configure an inbound port for basic authentication. Furthermore I had to produce a guide in order to being able to set it up in the same way in other environments.

Lucky for me, I found this great guide, that I would like to share. You can also use it as a template for configuring other types of authentication.


Posted in AIF, Microsoft Dynamics AX | Tagged: , , , | Comments Off on How to implement basic authentication in Dynamics AX2012 webservice

AX2012 CIL debugging

Posted by Torben M. Philippsen on February 22, 2016

AS You know there are a lot of guides out there on how to debug CIL. However when problems occur I find that quite a lot are missing some important things. So here’s my shot at a guide on how to debug CIL code.

In AX2012 some code is run in CIL (Common Intermediate Language). In general it means that our x++ code is compiled into .net. For instance batchjobs and other serverside code is run in CIL (unless configured otherwise).
If You want to read more regarding the background please visit this link – X++ compiled to .NET CIL.

Sometimes a mismatch can occur between the x++ code and the CIL code, and in these cases, it is nice being able to debug. I will try to list some important things that You may want to concider/check.

  • You will have to use at least VS 2010
  • I would recommend doing a local debug session – meaning your visual studio should be installed directly on the AOS. You can setup remote debugging but that just opens for a whole lot of new problems. Keep it simple – keep it on the AOS.
  • If possible You will prefer to have exclusive access – meaning no other users should be logged on. When debugging serverside code, you will hit every breakpoint triggered accross users. This means if you are debugging in an area where a lot of users are working, you will have to struggle with breakpoints being hit in a way you can’t possible imagine.

In order to configure your environment for CIL debugging You need to do this:

  1. Install VS2010/VS2012/VS2013 depending on your ax version on the AOS
  2. Run the Microsoft Dynamics AX Setup and choose to install the Visual Studio Tools.
  3. Generate/locate the sources
    When CIL compillation is performed it outputs .xpp files in C:\Program Files\Microsoft Dynamics AX\60\Server\<AOS_INSTANCE_FOLDER>\bin\XppIL and source files for Visual studio here C:\Program Files\Microsoft Dynamics AX\60\Server\<AOS_INSTANCE_FOLDER>\bin\XppIL\Source
    On some occations I have experienced the the source folder does not exist. In these cases stop the AOS service, delete all contents of the XppIl folder, restart the AOS (Maybe You need to perform a full CIL before). If you are not doing local debugging, You will need to setup a share for this folder.
  4. Configure the AOS for debugging. Go to the Dynamics AX Server configuration tool and be sure that the following checkmarks are set
  5. Launch visual studio in admin mode. Be aware that when VS connects to AX it uses the configuration from the client configuration tool. Make sure that you have set up the configuration you need – connecting to the correct layer etc (not important if you are just debugging).
    Launch the Dynamics AX Application Explorer to browse the AOT and set the breakpoints of your choice. When You double clikc a method a new solution is automatically created in solution explorer.
  6. Right click the newly created solution and select “properties”.
    Select “debug source files”.
    Add the path for the source files (local path or remote share)
  7. Now You are ready to attach Visual Studio to the AX32Serv process. Click the “Debug” menu item and select “attach to process”. Locate the AX32Serv process and attach to it. If VS is not in admin mode VS will now ask you to restart in elevated mode.
  8. Go back into AX and do the things you need in order to hit the breaktpoint.
  9. If You are not hitting any breakpoint you need to check, that you are set up to run code in CIL. Inside AX open a development environment. Go to Tools –> Options –> Development
    Make sure that the checkbox “Execute business operations in CIL” is checked.

Posted in Microsoft Dynamics AX | Tagged: , | Comments Off on AX2012 CIL debugging

Deadlocks show up in AIF exception log when CRM synchronizes multiple companies.

Posted by Torben M. Philippsen on January 25, 2016

Recently I was working on a case where some issues occured when trying to synhronize data between MS dynamics ax 2012 and MS CRM.

Scenario description:

In MS CRM the following maps have been set up for synchronization in two integrations.


Each integration uses its own AX user for connection.

From the CRM point of view, the synchronization seems to succeed. However going through the exception log in AX it seems that quite a few deadlocks have occurred, please see screendump below:


And here’s a screendump from the “general” tab showing the error message – “Cannot select a record in Change Tracking Version (AifSqlCtVersion). Change Tracking Version: 0.
Deadlock, where one or more users have simultaneously locked the whole table or part of it.


The deadlocks seems to have disappeared by themselves.
From this blog post this issue seems to be a known issue – – however the ax database had not recently been updated.


The cause:

The cause seems to be the SQL optimiser doing a clustered index scan (RecId) in the query below, resulting in blocking:



The solution:

  • Login to Dynamics AX –> Open a Development workspace, and navigate to AOT –> Dictionary -> tables,
    Find the table AIFSQLCTVERSION , and create a new non-unique index for CTVERSION field
  • Login to SQL server Management studio, and create a new plan guide for the query adding index hint
    GO(replace the index name I_100021KOO_CTVERSIONIDX with the actual name of the newly created index)


Posted in AIF, Microsoft Dynamics AX | Tagged: , | Comments Off on Deadlocks show up in AIF exception log when CRM synchronizes multiple companies.

Microsoft CRM: Synchronizing with multiple AX companies results in continuously opening new active AOS-connections

Posted by Torben M. Philippsen on January 25, 2016

Recently I was presented with a very interesting problem that occured when Microsoft CRM was synchronizing with Microsoft Dynamics AX 2012 using the DynamicsConnector for MS Dynamics AX. The installation guide can be found here.

In basics it was a standard setup in both ends. When syncing only one company everything would work just fine, but when syncing two or more companies the online users would be filled with active connections that wouldn’t close by themselves. In the end this would lead to the AOS not accepting new clients or even a crash due to lack of RAM.

The strange thing was that everything was setup according to the guidelines and was working fine in a reference environment. A MS support request was created and I will try to summarize all of our findings and the solution that fixed the problem.

The problem in short:

  • When running the synch of 2 or more companies simultaneously, the client session on AX continues to increase till the crash of AOS.
  • Running synch of 1 company only (in other words 1 integration) the client sessions do not increase; looks like they are recycled.
  • The problem occurs in all maps and seems to be a general problem in our scenario.
  • The synchronization for all companies is running on the same AX account.

The solution:

  • The verified solution from MS was to create separate accounts for each synchronization.

Posted in AIF, Microsoft Dynamics AX | Tagged: , , | Comments Off on Microsoft CRM: Synchronizing with multiple AX companies results in continuously opening new active AOS-connections

Troubleshooting problems related to integrating with third party components

Posted by Torben M. Philippsen on December 3, 2015

In AX you can comsume third party components in various ways – it could be a dynamic link library (dll) a webservice or maybe a quite different ressource. But whatever ressource  you are using, they all have one thing in common – it can be quite challenging when using them fails and You need to trouobleshoot, because AX is not particularly good in providing usefull error messages. In this post I will try to sum up some of my findings and maybe provide You with some tips on how to troubleshoot. Please feel free to contribute as I am sure my list of things isn’t nearly covering all scenarios.

The overall most common error is: “CLRObject could not be created” – no hints at all of what the problem might be… Here are some things you should consider…

When using dll’s or visual studio projects wihtin AX 2012 please consider Your CPU architecture. I quite often run into problems where everything works just fine when run on the client, but when running on the server it fails. This may be caused by the fact that the assembly is compiled for a specific architecture eg. x86. The ax client runs in 32 bit mode wheras the AOS server mostly runs in 64bit mode. And ofcourse this mismatch has to fail. Here’s what You should do:

  • If You are in control of the dll/assembly make sure it is compiled for any cpu.
    If using visual studio projects inside the AOT disregard the warning stating something about using different CPU architecture.
  • Make sure the dll doesn’t wrap other ressources. On one occasion I had a dll that was compiled for any cpu, but it wrapped a 32 bit COM object.
  • If you are not in control of the dll/assembly you can try and remove the corflag header (information about the bitness) using CorFlags –
    Another great post about Corflags can be found here –
  • If that doesn’t work and You are forced to use af 32 bit assembly on a 64 bit AOS, a good way to solve this would be to host the 32 bit dll/assembly in a webservice. This solution would provide a clean interface across the 32bit and 64 bit architecture.
    If You are in for a more hardcore solution maybe this would be of interest –
  • Make sure the dll/assembly is located in both client/bin on the client and server/bin on the AOS server. If using visual studio pojects wihtin ax, the deploy folder for the server is most likely server/bin/VSAssemblies. if using multiple AOS’es make sure the dll/assembly is deployed to all AOS servers. Remember to restart the AOS after deploy in order for the AOS to load it/them.
  • Make yourself aware of where the code is running – server or client? You need to know where the problem originates from.
  • If the dll originates from the “internet” make sure it’s not marked as “blocked” when viewing the file properties. Windows sometimes marks downloaded items as blocked.  
  • Another thing worth mentioning is having a proper error handling routine in your code. It might just provide You with some more clues about whats going wrong. Here’s what I usually do:

public void send2DLL()
    PRDeviceWrapper.XMLDevice   wrapper; //the assembly
    InteropPermission           interopPermission;

    str                         request;
    str                         answer;
    int                         returnValue;
    System.Exception            e;

    interopPermission = new InteropPermission(InteropKind::CLRInterop);


        wrapper = new PRDeviceWrapper.XMLDevice(); //<– this is where most errors occur     
        request = this.createRequest();
        returnValue = wrapper.RequestXML(request, byref answer);

    catch (Exception::CLRError)
        e = clrinterop::getLastException();

        while (e)
            e = e.get_InnerException();

    catch (Exception::CodeAccessSecurity)
        info("codeaccess error");

    catch (Exception::Internal)
        e = clrinterop::getLastException();

public static void showContainingAssembly(str _typeName)


   System.AppDomain appDomain = System.AppDomain::get_CurrentDomain(); 
   System.Reflection.Assembly[] assemblies = appDomain.GetAssemblies();
   System.Reflection.Assembly assembly;
   int numOfAssemblies = assemblies.get_Count();
   int i;  

   for (i = 0; i < numOfAssemblies; i++)
      assembly = assemblies.get_Item(i); 
      if (assembly.GetType(_typeName, false, true) != null)
         info(strFmt("Assembly full name: %1", clr2XppStr(assembly.get_FullName())));
         info(strFmt("Assembly location: %1", clr2XppStr(assembly.get_Location()))); 


Good luck…

Posted in Microsoft Dynamics AX | Tagged: | Comments Off on Troubleshooting problems related to integrating with third party components

CUES stopped working in RoleCenter

Posted by Torben M. Philippsen on November 27, 2015

Recently I was contacted by a customer who was in the process of upgrading some of the older windows server os’es. In that process the customer needed to move the AOS server from a specific server to another. Let’s call that server for AOS07. When stopping the AOS service on AOS07 the customer realized that cues in the rolecenter were missing/not working anymore. Starting the AOS service again fixed the problem, but ofcourse this was not the solution since the AOS07 had to be replaced.

After some analyzing I found that the sharepoint/EP server (Let’s call that server AOSEP) had its Ax client (business connector instance) configured to always connect to AOS07.

Let’s take a step back and think about what this means…

  • When a web-/rolecenter user connects to AX he will always connect to AOS07. That is how the business connector configuration were set up on AOSEP.
  • When stopping AOS07 cues stopped working. Ofcourse.

It all seems quite logical and ofcourse the solution was to change the business connector configuration on AOSEP to point to another AOS server.

Should You face a similar problem here’s a list of things You might want to check:

  1. Identify the server running the Sharepoint/EP site. You could get a clue about this by viewing the online users and see what server webusers connect to.
  2. Open the Dynamics AX client configuration on the EP/sharepoint server and have a look at the Business Connector configuration. The “connection” tab is the one you would like to check.
  3. If the BC configururation points to a specific server – maybe You want to switch to another
  4. Remember to restart the IIS
  5. I’m not entirely sure that it is necesarry but in may case I logged on to the AOSEP server using the identity of the business connector user.

Posted in Microsoft Dynamics AX, Rolecenter | Tagged: , | Comments Off on CUES stopped working in RoleCenter

AIF–duplicate types with name Dynamics.Ax.Application…

Posted by Torben M. Philippsen on May 11, 2015

In a recent task I had to redeploy an AIF http document service several times due to changes. Ocassionally the below error would occur when opening the inbound ports form. The error indicated that the classes related to my document service somehow would conflict because they were already registered. In the current state it would not be possible to activate a new inbound port.


Fortunateley a colleague of mine had experienced something similar and here is our guide that in the end solved my issue:

  • Create a job that deletes everything  from the SysXppAssembly

static void Job1(Args _args)
SysXppAssembly sysxppassembly;
delete_from SysXppAssembly;

  • Stop the AOS.
  • Delete all files (and folders) from the “C:\Program Files\Microsoft Dynamics AX\60\Server\[instancename]\bin\XppIL” folder
  • Start the AOS and go to Systemadministration/setup/services and application integration framework/inbound ports to check if the error has gone.

In most cases that would solve the problem. In one situation I experienced that the above gude was not enough. I also had to do the following:

  • compile the entire application
  • Perform full CIL
  • Restart the AOS

Hope this helps…

Thanks to Henning Ejner Andersen for assisting me on this issue.

Posted in AIF, Microsoft Dynamics AX | Tagged: | Comments Off on AIF–duplicate types with name Dynamics.Ax.Application…

AIf – Some or all identity references could not be translated.

Posted by Torben M. Philippsen on May 11, 2015

In a recent task i struggled with that error when calling an AIF http service. It would work from visual studios internal casini browser but when the client was deployed to IIS the error “ Some or all identity references could not be translated.” would display in the AIF exception log.

It was not possible to set up proper debugging in a timely manner so a little fix was created in order to being able to see why the error was being thrown.

Analyzing the labelid’s it turned out that the error with that labelid would only be thrown from one single location data dictionary/tables/AifPortUser. From there a call to to AifUtil::getWindowsUserSid(windowsUser) would occur causing the exception to be thrown. So the interesting thing would be to analyze what windows user actually was submitted by the client. In order to do that the AifUtil::getWindowsUserSid was modified in order to write the domain, alias and usersid to a text file:

        TextIo textIo;
        FileIOPermission fileio;   





        fileio = new FileIOPermission(@"C:\test\", #io_append);
        textIo = new TextIo(@"C:\test\textIOtest.txt", #IO_WRITE);
        textIo.write("domain: " + domain + "\n");
        textIo.write("alias: " + alias + "\n");
        textIo.write("userSid: " + userSid + "\n");

That little snipped showed that the identity of the default apppool was submitted and not the actual windows user. Changing the apppool identity fixed the problem.

Posted in AIF, Microsoft Dynamics AX | Tagged: , | Comments Off on AIf – Some or all identity references could not be translated.

SalesInvoice SSRS report shows without data

Posted by Torben M. Philippsen on April 28, 2015

At a customer the SalesInvoice SSRS report (AX 2012 RTM) was working inside the corporate network. From the DMZ zone the report would show up empty. Other reports would work just fine from the DMZ. No errors were displayed when executing the SalesInvoice report.

In order to narrow down the problem I the following things:

  • compared the C:\Program Files\Microsoft Dynamics AX\60\Server\Ax2012Prod\bin\XppIL folders of the two AOS’es.
  • I also tried restarting  the AOS
  • Doing a full CIL compile
  • Restarting the SSRS service from the “Reporting services configuration manager”

I am not sure what triggered the following error to display – but it suddenly clarified things a lot


The problem seemed to be causes by the buffersize in the AOS server configuration was set to the default value 24KB, which in this case was too small.
The error above would only be showed the first time the report was run after the restart. So it was sort of by coincidence that I discovered it.

Comparing the configuration of the internal AOS server with the AOS in the DMZ revealed that the buffersize was configered differently. The internal was set to a higher value than 24KB where the DMZ was set to the default value of 24KB. Changing the value in server configuration of the DMZ AOS solved the problem.

Usefull info about the buffersize:

  • AX2012 RTM has a default buffersize of 24KB
  • AX2012 R2 has a default buffersize of 48KB
  • Microsoft in general does not recommend going higher than 96KB

Please be aware that changing the buffersize will cause each client to consume just a little bit more of RAM. In light of that, it would be a good idea to monitor the performance over the next couple of days.

Posted in Microsoft Dynamics AX, SSRS | Tagged: , , | Comments Off on SalesInvoice SSRS report shows without data

Method not found: get_IsTempDb()

Posted by Torben M. Philippsen on April 28, 2015

Recently I was facing a strange thing with the Dynamics AX2012 SalesInvoice SSRS report. Running the report from the AX client caused the following error:


The error indicated that it had something to do with the metadata. I tried the following to resolve the problem:

  • Synchronize the database
  • Generating full CIL
  • Redeploying the report from AX
  • Opened and rebuilded the report i Visual Studio. Also did a redeploy from here.

None of the above actions helped.

Finally, in lack of better options, I restarted the SSRS service from the “Reporting Services configuration manager” – that did the trick – problem solved.

Posted in Microsoft Dynamics AX, SSRS | Tagged: | Comments Off on Method not found: get_IsTempDb()

%d bloggers like this: