Object reference not set to an instance of an object - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Object reference not set to an instance of an object

Last post 12-01-2008 05:04 AM by tylkomat. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 11-27-2008 01:36 AM

    Object reference not set to an instance of an object

    main data sourceHello there, I have 3 connected dropdown lists in my Infopath form. Selecting values from the first dropdown filters the entries in the second one and selecting a value in the second one will filter the entries of the third one. When selecting a value the second dropdown I get the "Object reference not set to an instance of an object" error. Despite of this error the form works just fine. It even retrieves the right values, but through the error it will not work as a browser form. Everything is located in my Main data source which you can see on the left side.

    When changing the second dropdown the function

    public void Artikelnummer_Changed(object sender, XmlEventArgs e)

    will be called.

    The pointer is now located at Artikelnummer. I want to retrieve the values for tempFarbe, but only if ddArtikelnummer matches Artikelnummer:

    XPathNavigator xnFarben = e.Site.SelectSingleNode("..//my:tempFarbe[../my:ddArtikelnummer = ../../../my:Artikelnummer]", NamespaceManager);

    When I now try to use the xnFarben object, I get the "Object reference not set to an instance of an object" error. When I move on the right values are in:

    String sFarben = xnFarben.InnerXml;

     

    I can't find any Error, I hope someone can help me.

    Thanks in advance

    regards Matthias

     

    PS: If you have problems with the german I can translate the names. But I don't think it will be necessary.

  • 11-27-2008 01:49 AM In reply to

    Re: Object reference not set to an instance of an object

    Could you show us the line of code that is generating the error, and perhaps a bit more of the code above and below it?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-27-2008 02:10 AM In reply to

    Re: Object reference not set to an instance of an object

    Hi,

    Since it is an Xpath issue we cant figure it out without knowing your main schema.So provide your schema so i can definitely help you.

    Chandrakanth/GGKTech
  • 11-27-2008 02:52 AM In reply to

    Re: Object reference not set to an instance of an object

    Jimmy:

    Could you show us the line of code that is generating the error, and perhaps a bit more of the code above and below it?

     

    Wow you guys are fast. Here is the complete function for the dropdown. I have a Sharepoint list from which I retrieve the values. The retrieving is done a dropdown before. The tempFarbe-value comes from a lookup inside that list. The tempFarbe holds then a String like: "2;#red;#23;#yellow" something like that, because of the lookup.

    public void Artikelnummer_Changed(object sender, XmlEventArgs e)

    {

    try

    {

    //MessageBox.Show(e.Site.SelectSingleNode("//my:tempFarbe[../my:ddArtikelnummer = ../../../my:Artikelnummer]", NamespaceManager).OuterXml);

    XPathNavigator xnFarben = e.Site.SelectSingleNode("..//my:tempFarbe[../my:ddArtikelnummer = ../../../my:Artikelnummer]", NamespaceManager);

    String sFarben = xnFarben.InnerXml;

     

    sFarben = sFarben.Replace(
    "#","");

    char[] split = {';'};

    String[] aFarben = sFarben.Split(split);

     

    List<XPathNavigator> nodesToDelete = new List<XPathNavigator>();

    foreach (XPathNavigator option in xnFarben.Select("..//my:ddFarbe", NamespaceManager))

    {

    nodesToDelete.Add(option);

    }

     

    //delete all nodes on the list

    foreach (XPathNavigator option in nodesToDelete)

    {

    option.DeleteSelf();

    }

    for (int i = 0; i < aFarben.Length; i++)

    {

    if (i % 2 == 1)

    {

    String sDDFarben = "<my:ddFarbe><my:ddFarbeNr>"+ aFarben[i-1] +"</my:ddFarbeNr>"+

    "<my:ddFarbeText>"+ aFarben[i] +"</my:ddFarbeText></my:ddFarbe>";

    xnFarben.SelectSingleNode("../my:ddFarben", NamespaceManager).AppendChild(sDDFarben);

    }

    }

    }

    catch(Exception ex)

    {

    MessageBox.Show("Message:\n" + ex.Message + "\nDetail:\n" + "\nStackTrace\n" + ex.StackTrace);

    }

    }

     

    chandrakanth:

    Hi,

    Since it is an Xpath issue we cant figure it out without knowing your main schema.So provide your schema so i can definitely help you.

    Don't you see the image ? This is the main schema. Can I retrieve the XML String of the schema somewhere ?

  • 11-27-2008 03:48 AM In reply to

    Re: Object reference not set to an instance of an object

    That code seems ok, but can you guarantee that the XPath "..//my:tempFarbe[../my:ddArtikelnummer = ../../../my:Artikelnummer]", will always find a matching node(i.e., that there will always be a child ddArtikelnummer that matches the grandparent Artikelnummer)?  If not, that error is going to occur.

     Does the stack trace that you are showing in the message box provide line numbers, and if so, which line in the code above is it pointing out as the line where the error occurred?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-27-2008 04:19 AM In reply to

    Re: Object reference not set to an instance of an object

    There are 3 drop down list in my form. The first lets you select a category, with this you will be able to select the articles of this category and through selecting an article you can select a color. The error occurs every time, if there are colors for an article or not.

    Artikelnummer is the value, which was selected from the dropdown. ddArtikelnummer are the values with which the dropdown list was filled.

    So there has to be always a matching one. tempFarbe is not filled every time, because not every article has a color, but that should not be the problem.

     

     The stack trace points to the line where I use the xnFarben object for the first time, which is line 307 String sFarben = xnFarben.InnerXml; in my code. But the string holds the correct value afterwards.

     

  • 12-01-2008 12:44 AM In reply to

    Re: Object reference not set to an instance of an object

    Are there any other ideas  regarding my problem ?

  • 12-01-2008 04:45 AM In reply to

    Re: Object reference not set to an instance of an object

    Hi,

    Try the following code.

    XPathNavigator xnFarben = e.Site.SelectSingleNode("..//my:tempFarbe[../my:ddArtikelnummer = ../../../my:Artikelnummer]", NamespaceManager);

    If(xnFarben == null)

    {

    return;

    }

    String sFarben = xnFarben.InnerXml;

    Write the next code lines.

    Swathip
    www.ggktech.com
  • 12-01-2008 05:04 AM In reply to

    Re: Object reference not set to an instance of an object

    Ah nice, thank you. It works now fine in the Infopath, but I get the following error when viewing the form in the browser.

     Unexpected end of file while parsing Name has occurred. Line 1, position 557.

    System.Xml.XmlException: Unexpected end of file while parsing Name has occurred. Line 1, position 557.
    at System.Xml.XmlTextReaderImpl.Throw(Exception e)
    at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
    at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String arg)
    at System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos)
    at System.Xml.XmlTextReaderImpl.ThrowTagMismatch(NodeData startTag)
    at System.Xml.XmlTextReaderImpl.ParseEndElement()
    at System.Xml.XmlTextReaderImpl.ParseElementContent()
    at System.Xml.XmlTextReaderImpl.Read()
    at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
    at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
    at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
    at System.Xml.XmlDocument.Load(XmlReader reader)
    at Microsoft.Office.InfoPath.Server.Xml.InfoPathXmlDocument.Load(XmlReader reader)
    at Microsoft.Office.InfoPath.Server.DocumentLifetime.DataObject.<>c__DisplayClass3.<.ctor>b__0()
    at Microsoft.Office.Server.Diagnostics.FirstChanceHandler.ExceptionFilter(Boolean fRethrowException, TryBlock tryBlock, FilterBlock filter, CatchBlock catchBlock, FinallyBlock finallyBlock)
    at Microsoft.Office.Server.Diagnostics.ULS.SendWatsonOnExceptionTag(ULSTagID tagID, ULSCat categoryID, String output, Boolean fRethrowException, TryBlock tryBlock, CatchBlock catchBlock, FinallyBlock finallyBlock)
    at Microsoft.Office.InfoPath.Server.DocumentLifetime.DataObject..ctor(EnhancedBinaryReader reader, Solution solution)
    at Microsoft.Office.InfoPath.Server.DocumentLifetime.DataObjects.<>c__DisplayClass2.<.ctor>b__0(EnhancedBinaryReader innerReader, DataObject& newObject)
    at Microsoft.Office.InfoPath.Server.Serialization.EnhancedBinaryReader.ReadObjectMap[KeyT,ValueT](Dictionary`2 map, ItemReaderDelegate`1 readKey, ItemReaderDelegate`1 readValue)
    at Microsoft.Office.InfoPath.Server.Serialization.EnhancedBinaryReader.ReadObjectMap[ValueT](Dictionary`2 map, ItemReaderDelegate`1 readValue)
    at Microsoft.Office.InfoPath.Server.DocumentLifetime.DataObjects..ctor(EnhancedBinaryReader reader, Solution solution)
    at Microsoft.Office.InfoPath.Server.DocumentLifetime.DocumentSessionState.DesterilizeVersion1(EnhancedBinaryReader reader, Solution solution)
    at Microsoft.Office.InfoPath.Server.DocumentLifetime.DocumentSessionState..ctor(EnhancedBinaryReader reader, Solution solution)
    at Microsoft.Office.InfoPath.Server.DocumentLifetime.DocumentSessionState.CreateFromByteArray(Byte[] serializedSessionState, Byte[] serializedVersionState, Solution solution)
    at Microsoft.Office.InfoPath.Server.DocumentLifetime.DocumentSessionStateManager.GetSessionState(HttpContext context, String editingSessionID, Solution solution)
    at Microsoft.Office.InfoPath.Server.DocumentLifetime.Document.LoadFromSession(HttpContext context, SPSite contextSite, EventLogStart eventLogStart, Solution solution)
    at Microsoft.Office.InfoPath.Server.Controls.PostbackPage.<>c__DisplayClass1.<ProcessRequest>b__0()

     

    Edit: Forget about that. I had an unused secondary Dataconnection.

    Thanks again to all who gave advice.

Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.