Declare XPathNavigator in Browser-Enabled Forms

D

Deniz Yalman

Hi,

How can i declare XpathNavigator for browser-enabled forms?

"Design Checker" forces me to use formstate property and doesnt allow member
variables. But if i declare XpathNavigator as a property and store in
formstate, it returns runtime error:

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="LeaveRequisitionForm"
StackTrace:
at LeaveRequisitionForm.FormCode.FormEvents_Loading(Object sender,
LoadingEventArgs e)
at
Microsoft.Office.InfoPath.Internal.FormEventsHost.OnLoad(DocReturnEvent
pEvent)
at
Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)
InnerException:


A code sample about using xpathnavigator in browser-enabled forms could help
me. Thanks in advance.
 
D

Don Reamey \(MSFT\)

The stack trace says that there is a Null Reference Exception.

Did you actually initialize your XPathNavigator object before it was used?

i.e.

private XPathNavigator _xpathNav
{
get
{
return (XPathNavigator)FormState["_xpathNav"];
}
set
{
FormState["_xpathNav"] = value;
}
}

public void InternalStartup()
{
_xpathNav = new XPathNavigator();
}

Just declaring the property does not create an instance of the object.


--
Don Reamey
Software Development Engineer
InfoPath Forms Server
Microsoft Corporation
http://blogs.officezealot.com/dreamey
 
D

Deniz Yalman

Thank you for warning me because i have missed to uncomment the instance and
gave you irrelevant error =)

This is a parf of my code:

public XPathNavigator _xpathNav
{
get { return (XPathNavigator)FormState["_xpathNav"]; }
set { FormState["_xpathNav"] = value; }
}

public void InternalStartup()
{
_xpathNav = this.CreateNavigator();
}

and i get a runtime serialization error:

System.Runtime.Serialization.SerializationException was unhandled by user code
Message="Serialization error."
Source="Microsoft.Office.InfoPath.Client.Internal.Host"
StackTrace:
at
Microsoft.Office.InfoPath.Internal.FormStateBagHost.System.Collections.IDictionary.set_Item(Object key, Object value)
at LeaveRequisitionForm.FormCode.set_thisXDocument(XPathNavigator
value)
at LeaveRequisitionForm.FormCode.InternalStartup()
at LeaveRequisitionForm.FormCode.FinishInitialization()
at
Microsoft.Office.InfoPath.XmlFormHostItem.Microsoft.VisualStudio.Tools.Applications.Contract.IEntryPointContract.FinishInitialization()
at
Microsoft.VisualStudio.Tools.Applications.EntryPointAdapter.Microsoft.VisualStudio.Tools.Applications.Contract.IEntryPointContract.FinishInitialization()
InnerException:

Actually this is my problem..
 
D

Deniz Yalman

XPathNavigator is not serializable. Because of this, it shouldnt store in
FormState.

public XPathNavigator _xPathNav
{
get { return this.CreateNavigator(); }
}

Solved.

Deniz Yalman said:
Thank you for warning me because i have missed to uncomment the instance and
gave you irrelevant error =)

This is a parf of my code:

public XPathNavigator _xpathNav
{
get { return (XPathNavigator)FormState["_xpathNav"]; }
set { FormState["_xpathNav"] = value; }
}

public void InternalStartup()
{
_xpathNav = this.CreateNavigator();
}

and i get a runtime serialization error:

System.Runtime.Serialization.SerializationException was unhandled by user code
Message="Serialization error."
Source="Microsoft.Office.InfoPath.Client.Internal.Host"
StackTrace:
at
Microsoft.Office.InfoPath.Internal.FormStateBagHost.System.Collections.IDictionary.set_Item(Object key, Object value)
at LeaveRequisitionForm.FormCode.set_thisXDocument(XPathNavigator
value)
at LeaveRequisitionForm.FormCode.InternalStartup()
at LeaveRequisitionForm.FormCode.FinishInitialization()
at
Microsoft.Office.InfoPath.XmlFormHostItem.Microsoft.VisualStudio.Tools.Applications.Contract.IEntryPointContract.FinishInitialization()
at
Microsoft.VisualStudio.Tools.Applications.EntryPointAdapter.Microsoft.VisualStudio.Tools.Applications.Contract.IEntryPointContract.FinishInitialization()
InnerException:

Actually this is my problem..

Don Reamey (MSFT) said:
The stack trace says that there is a Null Reference Exception.

Did you actually initialize your XPathNavigator object before it was used?

i.e.

private XPathNavigator _xpathNav
{
get
{
return (XPathNavigator)FormState["_xpathNav"];
}
set
{
FormState["_xpathNav"] = value;
}
}

public void InternalStartup()
{
_xpathNav = new XPathNavigator();
}

Just declaring the property does not create an instance of the object.


--
Don Reamey
Software Development Engineer
InfoPath Forms Server
Microsoft Corporation
http://blogs.officezealot.com/dreamey
 

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