Invalid Cast Exception...

E

educos

Hi,

When I run this piece of code from a Windows Form program, I get an invalid
cast exception when I try to access the Errors property of XDocument
interface...
Why ?

ApplicationClass app = new ApplicationClass();
XdDocumentVersionMode mode = XdDocumentVersionMode.xdCanOpenInReadOnlyMode;
int numMode = (int)mode; // =8
XDocument form = app.XDocuments.Open(@"MyForm.xml", numMode); // ==> ok, I
can see the form opened in Infopath
ErrorsCollection ec = form.Errors; // ==> "Invalid cast exception" !!!!
int countErrors = ec.Count;
app.Quit(false);

What I want to do is to open a set of infopath forms and verify that all
forms are valid .
 
F

Forrest Dillaway

The product team has been made aware of this issue when automating InfoPath
externally. They are following up internally.

There is a workaround for this issue (I haven't compiled, so you may have to
play with it a bit :)):

Replace:
ErrorsCollection ec = form.Errors;
With:
Errors errors = form.GetType().InvokeMember("Errors",
System.Reflection.BindingFlags.GetProperty, null, form, null) as Errors;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top