I am using WPF .NET Core 3.1
app to automate Microsoft WORD
. As we know Office COM
references don't work with .NET Core 3.1. But there is a workaround as explained here or as explained in the Note
section here in an official .NET Core Excel sample or another workaround explained here.
The above mentioned workarounds work in almost all cases in my WPF Core 3.1
app for WORD
automation except in some cases such as the one shown below where I get the following error at the last line of the code:
Code:
....
using WORD = Microsoft.Office.Interop.Word;
oApp = new WORD.Application();
oApp.Visible = true;
WORD.Document oDoc = oApp.Documents.Open(@"C:\tmp\Test.docx");
string st = oDoc.Paragraphs[1].Range.Text; //this line correctly shows the content of Paragraph[1]
st = oDoc.Paragraphs[1].get_Style().NameLocal; //this line throws the error shown below
Error:
System._ComObject does not contain a definition for NameLocal
Remark: The above error does not occur in my similar project in WPF .NET FullNetwork
app. And there it correctly displays the value of oDoc.Paragraphs[1].get_Style().NameLocal
as Normal
if the paragraph is a normal paragraph, or it displays, say, Heading 1
if paragraph is a Heading 1 etc.
Question: What could be the cause of the error in the above WPF .NET Core 3.1
app and how can we remedy it?