简体   繁体   中英

vb.net Xmldocument, selectSingleNode only returns value with vs2008 “watch” utility

I have a problem with the selectSingleNode function.

Context: In a program I need to perform some subsequent filters, normally I have no problems on those, But this time I have a weird "bug".

I have the next code:

Dim test As XmlNode = parentXmlnode.SelectSingleNode("day[@date='" & fecha.Date.ToString("o") & "']"


Problem: When I debug/run the code above, the variable "test" alwas have NOTHING, but If I apply a "watch" on the "selectSingleNode" instruction it does return an XmlNode.

No matter if I go back and re-degug this part of the code, the result is always the same.

Of course the code above is an oversimplification of the original code, here is the untouched original code that causes the problem:

EDIT : The full code wasnt necessary, in fact it make the question hard to read, the error is in the line of code exposed before.

Any information is highly appreciated. Thanks In Advance.

the error was in the " fecha.Date.ToString("o") " part of the code.

When I use the watch utility on that part i get the DateTimeKind.Unspecified format of the ISO 8601 (2009-06-15T13:45:30.0000000)

but when the code was interpeted, the program got the DateTimeKind.UTC format of the ISO 8601 (2009-06-15T13:45:30.0000000Z)

I have discovered this by using and intermediate String variable to store the xpath filter. I dont know why the watch utility changes my result, maybe has Heisenberg's particle complex ,

but the correction was using a "datetime" intermediate variable specifically declared as datetimekind UTC :

Solution :

Dim fechaAux As String = New DateTime(fecha.Ticks, DateTimeKind.Unspecified).ToString("o")
Dim test As XmlNode = parentXmlnode.SelectSingleNode("day[@date='" & fechaAux.Date.ToString("o") & "']"

This stuff keept me delayed for days, I hope someone find this question/answer useful.

Best Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM