Sunday, 31 January 2016

X++ in AX7: Method signatures

This
post is about one of the more subtle changes in AX7. AX7 uses the .NET
runtime, aka CLR. This has some implications for method signatures. In
the CLR a method's signature includes casing, parameters and return
type. In AX2012 a method's signature was simply the method's name – case
insensitive.

Why is this important? If you change a method's signature, then all
references to the method needs to be recompiled. Including those changes
that appear harmless, like:

Here is an example, where I changed the casing of a method, that is being consumed by a test. I did NOT recompile the test before running it.

Notice the System.MissingMethodException: Method not found: 'Void
Dynamics.AX.Application.MyClass.myMethod()'. The CLR only knows of a
method with all lower case.

Optional parametersIt is still safe to add and
remove (unused) optional parameters. The X++ compiler uses CLR's method
overloading, i.e. several methods with the same name and the variations
of supported parameters are produced by the compiler.

Lesson to learnDo not change a method's signature, unless you are willing (and able) to recompile all consumers.