Hi Team,
I have placed only the below line in my test application using VSTO Word Add-in c#. I have refered all the required dll files into my reference. When I run the application I am getting null reference error in the below line. Can anyone help me to fix the issue or I missed anything.
private Microsoft.Office.Interop.Word.Application wordApp = Globals.ThisAddIn.Application;
Hazique MohammadPosted Apr 29, 2025, 9:28 AM
Hi
Daniel WrightPosted Apr 29, 2025, 9:13 AM
It seems like you are encountering a null reference error when trying to access the `Application` property in your Word add-in. This type of error usually occurs when you are trying to access a member of an object that is currently set to null, meaning it does not refer to an instance of an object.
In your case, the line of code `private Microsoft.Office.Interop.Word.Application wordApp = Globals.ThisAddIn.Application;` is attempting to assign the Word application object to `wordApp` variable. The `Globals.ThisAddIn.Application` should provide you with the reference to the Word application object associated with your add-in.
To troubleshoot the null reference error, you may want to check the following:
1. Ensure that your Word add-in is properly initialized before accessing the `Application` property. Make sure that the `ThisAddIn_Startup` event or a similar initialization method has been triggered.
2. Verify that the `Globals.ThisAddIn.Application` is not null before assigning it to `wordApp`. You can add a null check to handle this scenario.
3. Double-check that all necessary references are properly added to your project, especially the `Microsoft.Office.Interop.Word` reference.
Here's an example of how you could add a null check before assigning the Word application object:
By incorporating these checks and ensuring proper initialization, you should be able to mitigate the null reference error in your Word add-in application. If the issue persists, feel free to provide more details for further assistance.