Microsoft KB Archive/925185

= Error message when you run a C# application that uses the Word 2007 object model: &quot;Unhandled Exception: System.ArgumentException&quot; =

Article ID: 925185

Article Last Modified on 10/15/2007

-

APPLIES TO


 * Microsoft Office Word 2007

-



SYMPTOMS
You run a C# application that adds custom XML to a Microsoft Office Word 2007 document by using the Word 2007 object model. When you do this, you may receive the following error message:

&quot;Unhandled Exception: System.ArgumentException: This operation failed because one or more changes made during events were invalid.at Microsoft.Office.Core.CustomXMLPartsClass.Add(String XML, Object SchemaCollection) at .Main(String[] args)&quot;



CAUSE
This issue occurs when the C# application contains the following line of code: WordApp.ActiveDocument.CustomXMLParts.Add(null, null);



WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

To work around this issue, replace the line of code that is listed in the &quot;Cause&quot; section with the following line of code: WordApp.ActiveDocument.CustomXMLParts.Add(ref missing, ref missing);

Additional query words: wd12 wd2007 wd2k7 Word12 Word2007 Word2k7 2k7 12

Keywords: kberrmsg kbtshoot kbcodesnippet kbprogramming kbprb kbexpertiseinter KB925185

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.