How to add .dll file into AX 2012

When I was trying to add a .dll into AX 2012, I could not find a document how to do that. After many testings I did, eventually, I figured out how it works. Basically, this post is for those developers who have not used .dll in AX 2012. Hope it could help them understand how to do it.
I found that to let AX use the .dll we need to,

1. Let AX know that .dll, so we can compile the code.

  • Add reference

If the .dll is already added to GAC on the client machine, we can select it from the assembly list. Otherwise, we'll need to select the .dll file by browsing the file.

  • If .dll is not in GAC on the client machine, we additionally need to copy the .dll file to the client/bin folder and restart the client so we can compile the code which consumes the .dll. 

2. Let AX be able to find the .dll to consume it.

  • If the code is run at server side, we need to make sure the .dll could be correctly consumed. So we need to either add that .dll to GAC on the server machine or add it to server/[InstanceName]/bin folder and restart the AOS.
  • If the code is run at client side, we need to do the same to the client machine.

Once we've done above, the .dll should be able to be called by AX 2012.


How to email report in AX 2012 without outlook?

In out of box AX 2012, user has to have outlook to mail the report which is kind of anoying, cause not all of the AX user has outlook. We can find code snipet to bypass outlook to do that online, but you'll notice those codes are only for the old AX report instead of SSRS report. In AX 2012,  the reports are all SSRS reports which means we cannot modify the code in Info\reportSendMail as we did for AX 2009 to bypass outlook.
In fact, it's even easier to do that in AX 2012. In AX 2012, when mailing reports, the class 'SrsReportRunMailer' is executed. What we need to do is just change that class. If you open that class, you'll see the method 'initMailer' decides whether to use SMTP or outlook. When mailing in a batch, it uses SMTP, but when mailing at client, it uses outlook. To change the logic to always go with SMTP, we only need to comment out the 'if' clause and leave the code which takes SMTP. See below,

private void initMailer()
    fromAddress = SrsReportRunMailer::buildFromEmailAddress();
    // Always use SMTP, never outlook.
    //if (isRunningOnServer())
        // get the mailer object
        mailer = this.parmSysMailer();

        // validate the from email addresses
        if (!fromAddress ||
            error(strfmt("@SYS134596", "@SYS4083"));
        //inetMailer = new SysINetMail();


Access the private project created by other users

Sometimes we do want to access the private project created by other users, e.g. when importing a model we get a private project conflict, to resolve this we have to find the project and delete it. If the owner of those projects are gone, we'll not be able to access them as normal, we'll have to do something unusual to get it.
Even though there're many different approaches to get this resolved in others' blogs/forum, I found my way is probably easiest. Here it is,
1. Find the AX database on SQL server.
2. Open table ModelElement with the private project type only.The private project type is 38.
3. Change the prefix of the private project you are looking for from the original user Id to your user Id by a simple update like.
  update [AX1111_2].[dbo].[ModelElement]
  set Name = 'Admin_AOTExport2012_DynamicsPerfDirect'
  where Name = 'JasonPAdmin_AOTExport2012_DynamicsPerfDirect' and ElementType = 38
4. Reopen AX client with your account, and you'll see the project appears in your private project