Tag Archives: X++

Cannot add or remove static keyword for this method

A while ago while delivering code for a customer (in Microsoft Dynamics AX 2012) I ran in to this problem while compiling with axbuild.exe (but not while compiling in the aot).
I haven’t been able to reproduce this error after fixing the problem, but from what I read there might be several ways to reproduce it.

So, how did I fix this?
First things first.. What does the error message mean and why does it only appear while using axbuild.exe?
Since last compilation of the object the static keyword on the method you are trying to compile has been removed or added.
When the static keyword is being added/removed you are note only changing the plain text code of the method, but also the type of the object.

The type of an aot object is stored in the model database in the table “ModelElement”.
As you can see there is a field named “ElementType”.
2016-05-30 16-52-35

And here is Microsoft’s list of types.

The problem when you get this error message is that the element type is not in sync with the plain text code.
For example: Your method is saved as a static method, but in the “ModelElement” table the element type is still 12 (TableInstanceMethod) where it should be 22 (TableStaticMethod).
For some reason the compiler in the aot does not validate this, but the axbuild.exe compiler does.

Here is a comparison I did between the source and destination environment during my installation of code.
5FFA24F0

Changing this directly in sql with “Sql Server Management Studio” will do the trick.