If you’re running a 64-bit Windows Server and using C# to automate Microsoft Word via Interop, you may encounter a frustrating null reference error on the following line:
var appWord = new Microsoft.Office.Interop.Word.Application();
var wordDocument = appWord.Documents.Open(inputFile); // Fails here
This error happens because Microsoft Word Interop expects a “Desktop” folder within the system profile directory, which isn’t created by default on 64-bit Windows Server installations.
The Solution
To resolve this error, manually create a “Desktop” folder in the following location:
Copy code
C:\Windows\SysWOW64\config\systemprofile\Desktop
Here’s how to do it:
- Open File Explorer and navigate to
C:\Windows\SysWOW64\config\systemprofile\
. - Right-click and create a new folder called
Desktop
.
After this, try running your code again. This simple fix should resolve the null reference error, allowing your Word Interop automation to work as expected on 64-bit Windows Server environments.