Debugging TF Build template for AX

I’m preparing a build of a Dynamics AX 2009 environment using Team Foundation Server 2013 and libraries from Dynamics AX Admin Utilities. Unfortunately the build failed with the following error:

Exception Message: Object reference not set to an instance of an object. (type NullReferenceException)
Exception Stack Trace:    at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
   at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

It says that there is a null reference somewhere, but it doesn’t say where, which isn’t very helpful.

I opened the block in my build template which handles exceptions (named If a Compilation Exception Occurred) and added one more action before rethrowing the exception.

Activity: WriteBuildError
Message property: compilationException.ToString()

Just getting a string representation of the exception may not look useful, but it did help. This is the message I got in build output:

System.NullReferenceException: Object reference not set to an instance of an object.
   at CodeCrib.AX2009.Client.Client..ctor()
   at CodeCrib.AX2009.TFS.ImportXPO.BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, Object state)
   at System.Activities.AsyncCodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

It looks similar, but it’s much more useful. It tells me that the NullReferenceException occurred inside a constructor of Client class in assembly CodeCrib.AX2009.Client. That’s much more specific.

When reviewing the constructor, I noticed it tries to access a registry key (HKEY_CURRENT_USER\Software\Microsoft\Dynamics\5.0\Setup\Components) to find where AX client is installed. I know that these registry keys don’t always exist and I verified that this was the case with my build service too. I created registry keys by running AX configuration utility, started a new build and voilà – there is no NullReferenceException anymore.

One Comment

Leave a Reply

Your email address will not be published.