Microsoft Dynamics AX Support

This blog contains posts by the Microsoft Dynamics AX Support Teams Worldwide

Unable to import model files generated using Export-AxModel cmdlet, or upload it to LCS for Customization analysis

I wanted to share an issue you may face when exporting models using the AX 2012 powershell cmdlets. As per the system requirements, we recommend using Powershell v2.0. However you may have Powershell v3 and above installed on your system (like Windows Server 2012 R2), and this can cause the following issues:

 

Issue 1:

Unable to import models using AXUTIL.EXE, where the models were created using Powershell cmdlet Export-AxModel.

To demonstrate the issue create a custom model file, in this example we refer to a model called “Demo Model”

 

(a)   
Example, run the AX Management Shell and then run the following command to export a custom model called ‘Demo model’

Export-AXModel -model “DEMO MODEL” -file c:\temp\demo1.axmodel

 

(b)  
Run an elevated cmd prompt and import demo1.axmodel using axutil.exe:

axutil import /file:c:\temp\demo1.axmodel

 

We get an error:

ERROR: Could not load file or assembly ‘C:\TEMP\demo1.axmodel’ or one of its dependencies. This assembly is
built by a runtime newer than the currently loaded runtime and cannot be loaded.

 

(However importing the same model using Install-AXModel  cmdlet works fine).

 

(c)
Or if you import the model in to your LCS Project (https://lcs.dynamics.com) under the “Customization analysis” tool, you will get an error as follows:

Only models exported with AxUtil version 6.3.164.2431 or lower can be uploaded to this project

 

 

Issue 2:

Also notice that the same model exported by powershell cmdlet is a different file size, compared to it being exported by axutil.exe

 

(a)   
e.g. Export the ‘Demo Model’ using axutil.exe

axutil export /model:”DEMO MODEL” /file:c:\temp\demo2.axmodel

 

(b)  
Now compare file sizes of demo1.axmodel and demo2.axmodel, and notice that demo1.axmodel file is
slightly smaller.

 

 

Cause:

Powershell v3 and above uses a different Microsoft .NET Framework build then v2.

 

 

SOLUTION:

This issue can be resolved by enforcing the AX Management Shell to use Powershell  Version 2 framework instead as follows:

 

(1)   
Secondary mouse-click on the “Microsoft Dynamics AX Management Shell” icon in “Administrative tools” and select properties.

 

(2)   
By default it will have the following target cmdline (or something similar):

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -NoExit & ‘C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities\Microsoft.Dynamics.ManagementUtilities.ps1’

 

(3)   
Change the target cmd line on your system by adding one more argument: -Version 2 as follows:

 

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Version 2ExecutionPolicy RemoteSigned -NoExit & ‘C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities\Microsoft.Dynamics.ManagementUtilities.ps1’

 

Now you should be able to create the correct model file format when running the Export-AXModel cmdlet in the “Microsoft Dynamics AX Management Shell”.