Click to See Complete Forum and Search --> : Microsoft.Office.Interop.Word Warnings : What to to against ??


JonnyPoet
March 19th, 2009, 09:04 AM
I have the following codetry {
//try to open the document
docRef = wordApp.Documents.Open( ref file, ref missing, ref readOnly,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible,
ref missing, ref missing, ref missing, ref missing);
wordApp.Visible = false;
// some actions done like
docRef.ActiveWindow.Selection.WholeStory();
docRef.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
_rtbDoc.Paste();
//...
} catch (Exception ex) {
throw ex;
}
finally{
object boolObj = (object)false;
docRef.Close(ref boolObj, ref boolObj, ref boolObj);
wordApp.Quit(ref boolObj, ref boolObj, ref boolObj);
}
The read shows lines both give me a warning which translated from german is still strange as I dont know how to handle that it says

Multisignificance between
Microsoft.Office.Interop.Word._Document.Close(ref object, ref object, ref object)-Method and the 'non method '"Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close". A methodgroup is used verwendet. ( pointing to the line where I do docRef.Close(....) )

The other one is
Multisignificance between Microsoft.Office.Interop.Word._Application.Quit(ref object, ref object, ref object)-Method and the non method "Microsoft.Office.Interop.Word.ApplicationEvents4_Event.Quit". A methodgroup is used. ( This points to the line where I use wordApp.Quit(...)

But the program itself seems to work properly. But there can occure some events where I found out that WinWord.Exe in the Taskmanager still hangs around so I want to find out what this erromessage should be and how to get a reliable method to close my hidden called word application, because I have seen if it wasn't correctly closed by my application it can create problems when my code is trying to open another document with the same method.

MNovy
March 19th, 2009, 09:57 AM
lol, I know these warnings and I just ignore them,
since I did not figure out how to solve them via correct code.

But since there is no side effect, it seems to work without problems also in my case.

JonnyPoet
March 19th, 2009, 10:46 AM
lol, I know these warnings and I just ignore them,
since I did not figure out how to solve them via correct code.

But since there is no side effect, it seems to work without problems also in my case.Yea its a bit strange as they have nothing to do with what is the code and what is the warning, only the word 'Close' and 'Quit' matches, :D also the expression 'non method' , what should a 'non method' be a Property ? But a Property wouldn't have Clauses so the compiler should be able to differ between a method and a property.

As you obviously have experience with that. How do you secure the access to word docs against exceptions
If I do the whole thing into one try catch and it fails it could happen the application doesn't get closed. If I do the 'doc.Close(...) and the 'app.Quit(...)' into the finally block it could happen the application has already failed to open so the doc wouldn't even have been created. This case an exception would be thrown within the finally block isn't it ?
Does word return null if it wasn't able to create the application or the document ? And what happens if you try to close an already closed document (closed by an exception maybe ) or to quit an already quitted application ?
is there a 'Standard way' to have a word document opened and closed and preventing it in any case not to be correctly closed by may application ?

sotoasty
March 19th, 2009, 02:09 PM
is there a 'Standard way' to have a word document opened and closed and preventing it in any case not to be correctly closed by may application ?

I generally group by object, and OR create a sub or function for sub functions. So Word Application goes into the main function. Word Document code gos in sub function.

Or as posted below, a sub try.


try {
/ Intialize the Word application here.
try {
//try to open the document
docRef = wordApp.Documents.Open( ref file, ref missing, ref readOnly,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible,
ref missing, ref missing, ref missing, ref missing);
// some actions done like
docRef.ActiveWindow.Selection.WholeStory();
docRef.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
_rtbDoc.Paste();
} catch (Exception ex) {
throw ex;
}
finally{
object boolObj = (object)false;
docRef.Close(ref boolObj, ref boolObj, ref boolObj);
}
} catch (Exception ex) {
throw ex;
}
finally{
object boolObj = (object)false;
wordApp.Quit(ref boolObj, ref boolObj, ref boolObj);
}