Adding AD User to SharePoint Group Dll as a reference - AX2012 FP CU3.

Hi All,

Recently I have faced an issue when using the references.


My DLL does the operation of adding AD users to SharePoint user group.

Its working fine when I try in Visual studio 2010.

But after adding as a reference in AX2012 I’m receiving the following error, when I try accessing that dll thru job.


“Error in System.Exception Retrieving the COM class factory for component with CLSID {BDEADF26-C265-11D0-BCED-00A0C90AB50F} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).”

Solution tried:

  1. Changing the platform target to x64 bit in Visual studio 2010.

Notes: After building the project in x64 bit, I was getting “Variable **** has not been declared” error.

  1. Tried as Mr. Martin Dráb suggested "">…/338155.aspx"

Still the error exists.

Can anyone suggest me an solution?

Is your code running on AOS? AX client is a 32-bit process.

Yes. Running in AOS server

One more attempt - if AOS is on a different machine than Visual Studio, your test in VS doesn’t prove that it works. Maybe the COM object isn’t really registered on the machine with AOS.

Also, the AOS service may not have permissions to use the COM object (see Security in COM).


If it is AX 2012 and you are using C# dll, then it is not required to add the dll as reference. Try the following -

  1. From Visual Studio add the project into Dynamics AX and check whether it gets deployed error free into AX
  2. Then from AX do full CIL compile
  3. Now you should be able to access this dll from within AX by referring to ‘Namespace.Class.’

@Martin - AOS and Visual studio is installed in same machine.

Then, my visual studio project does Creation of AD users and changing AD password and Adding AD user to SharePoint 2010 user Group.

In which I’m getting this error only while accessing the “Adding AD user to SharePoint user group” method through the JOB.

Regarding DLL register : I have added the DLL in GAC, x64 bit DLL in Server/bin folder and x86 bit DLL in Client/bin.

Is there anything I missed?

Looking forward for your suggestion to proceed.

@Harish: I have no problem in adding the dll reference and accessing other methods from my dll thru X++ Job.

I have a problem only when I try accessing the “Adding AD user to SharePoint 2010” method.

Can you help me in sorting this out?

Can you show us your job?

By the way, don’t spend time to install the library everywhere - the code already runs, the problem is in creating the COM object.

Below is the sample job to create AD user and Add user to SP group.

static void CreateNewUserInArabicEP(Args _args)
MyDll.class1 obj;
str strReturn;

obj = new MyDLL.Class1();
//strReturn = obj.CreateADUser(“User”,“Domain”,“AdminName”,“AdminPassword”); // Creating AD user
strReturn = obj.AddUserInEP(“User”,“UserGroup”); //Adding user to SP2010


Pleas advise

Hi Pradeep,

This could be a permission related issue. Try the following -

  1. Put the above above code in a class method

  2. Create a wrapper method for executing the above method. Use ‘runAs’ function ( for executing the above method using ‘Admin’ user

  3. Now call the above method from Ax job.

If you simply run the job, it’s executed on client, i.e. in a 32-bit process and the 64-bit COM object fails to create.

Hi Martin,

I tried running through RunBaseBatch, I’m getting the following error:

“Error in System.Exception Microsoft SharePoint is not supported with version 4.0.30319.586 of the Microsoft .Net Runtime.”

Suggest me…

Will you get the same error in Visual Studio if you build your project for .NET 4? Can you get call stack of the exception?