web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to use "microsoft.office.interop.word" in batch execution (on server-side) in AX 2012?

(0) ShareShare
ReportReport
Posted on by 50

Hi all,

I need to convert some .docx into PDF and this process needs to be executed in batch. I have decided to use "microsoft.office.interop.word", so I made a development in .NET and called the assembly reference in AX 2012.

This is my C# code:

using Microsoft.Office.Interop.Word;

            Application word = new Application();
            Document     doc = word.Documents.Open(@"test.docx");

            doc.Activate();
            doc.SaveAs2(@"test.pdf", WdSaveFormat.wdFormatPDF);
            doc.Close();

            word.Quit();

If I run code client-side, I do not have problem, otherwise if I run code in batch (on server-side): 

word.Documents.Open(@"test.docx");

return NULL value, then I catch this exception in AX:

"System.NullReferenceException: Object reference not set to an instance of an object."

at line doc.Activate();

Other points:

-MS Word is installed on AOS.

-CIL is correctly compiled.

It seems to be a security problem server-side that blocks process, what do you think about?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    301,075 Super User 2025 Season 2 on at

    Hi Giuseppe,

    Have you checked if the code is running on the AOS if you are using a local client on that machine? If so, have you created a specific method for running the batch in IL language?

    Probably the blog from Joris will help you: daxmusings.codecrib.com/.../x-in-net-clr-life-in-fast-lane.html

  • Giuseppe Scaltrito Profile Picture
    50 on at

    Hi André,

    yes I have. I extend RunBaseBatch for running my code. It's running in IL language for sure. Meanwhile I found this, it could be helpful:

    support.microsoft.com/.../considerations-for-server-side-automation-of-office

    For my purpose I decided to use an external product in order to rendering my documents.

    Thanks for your help!

    Regards.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans