Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27201

VS 2012 XDocument - Object reference not set to an instance of an object

$
0
0
Hi,

got a little problem with XDocument. I use XDocument to get a value from an XML document. Everything is working fine but I get an error (Object reference not set to an instance of an object) when I try to debug the project...but it's working when I click next. This is my code:

Code:

Dim cbt As String
I do assign the value from a combobox and I can display cbt so the value seems to be assigned correctly
Code:

cbt = ComboBox1.Text
Then I start the sub with XDocument
Code:

Dim materialXDoc = XDocument.Load("C:\Test\Material.xml")
        Dim groupXDoc = XDocument.Load("C:\Test\Zerspanungsgruppen.xml")

        'Hard coded in this example you said you get it from a combobox selection
        Dim searchValue = cbt

        'Search for a specific name in materialXDoc and get the value of the Zerpspanungsgruppe node
        'Will return Nothing if the search value is not found
        Dim searchedgroup = (From n In materialXDoc...<Material>
                                        Where n.@name = searchValue
                                        Select n.<Zerspanungsgruppe>.Value).SingleOrDefault()

        'Search the Zerpspanungsgruppe.xml file and return the spezSchnittkraft and AnstiegswerMc node values
        'Will return nothing if the search value is not found
        Dim correspondingValues = (From n In groupXDoc...<Zerspanungsgruppe>
                                  Where n.@name = searchedgroup
                                  Select New With {.SpezSchnittkraft = CInt(n.<spezSchnittkraft>.Value), .AnstiegswertMc = CDbl(n.<AnstiegswertMc>.Value)}).SingleOrDefault()
        Dim ssk = correspondingValues.SpezSchnittkraft
        Dim amc = correspondingValues.AnstiegswertMc
        Label3.Text = ssk
        Label4.Text = amc

The error (Object ...) is pointing to "Dim ssk = correspondingValues.SpezSchnittkraft" but yeah, when I click on next and ignore the error everything is working

Viewing all articles
Browse latest Browse all 27201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>