最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

The Registry.CurrentUser impediment

AX 2012 Kenny Saelen 1094浏览

Today I was working on creating a build process template for AX2012. I will not go into the details about the build process template and the custom activities as these activities will be covered by Joris De Gruyter later on. But still, I wanted to show you guys a nasty little problem I was experiencing yesterday.

The build process threw an exception : ” Object reference not set to an instance of an object

So, this was of course a null reference, but after some investigation ( by using primitive logging because this was running in the agent process :-) ) it turned out to be located in this code:

public static string GetInstallDir32()
{
    RegistryKey componentsKey = Registry.CurrentUser.OpenSubKey(regKey, false);
    String installDir32 = componentsKey.GetValue("InstallDir32", null) as String;
 
    return System.Environment.ExpandEnvironmentVariables(installDir32);
}

It turned out to be the Registry.CurrentUser property that returned null. And then it struck me, the agent ran under a service account s_tfs_build and since this account was never used to log on interactively, the profile of this user was not loaded up to that point.

The simple solution was to log on to the system with the service account so that the user profile and registry hive were loaded. From then on, the Registry.CurrentUser property was properly filled.