LINQ and XML for compact framework

W

Wan

That's focusing on the debugger side of things, which I believe is a
red herring. Concentrate on diagnostics which don't require the
debugger.


So if you put a call to MessageBox.Show in the foreach loop, having
removed the where clause, you're still not seeing anything? That's
worrying.

When you a call to MessageBox.Show in the exception handler, did it
show any exceptions being thrown?

If you put a call to MessageBox.Show after the call to Save(), did it
show the code getting there successfully?

Jon

Yes, I still see nothing. And the {"NullReferenceException"} was
thrown. the Save() statement was not excuted.

Wan
 
J

Jon Skeet [C# MVP]

Yes, I still see nothing. And the {"NullReferenceException"} was
thrown.

Ah! Now we're getting somewhere! So what was the stack trace? Where
was the exception being thrown?
the Save() statement was not excuted.

No wonder, if an earlier statement was throwing an exception. This is
why it's a really bad idea to swallow exceptions without logging
them :)

Jon
 
W

Wan

Ah! Now we're getting somewhere! So what was the stack trace? Where
was the exception being thrown?


No wonder, if an earlier statement was throwing an exception. This is
why it's a really bad idea to swallow exceptions without logging
them :)

Jon

The exception was thrown inside the foreach statement. After it
excute
el.Element("MessageStaus").SetValue(newStatus.ToString());
this line of code, the exception was fired.


Here is the stack trace:
at xmlCFtest.Form1.updateMsg(String MsgID, Int32 newStatus)
at xmlCFtest.Form1..ctor()
at xmlCFtest.Program.Main()

Wan
 
J

Jon Skeet [C# MVP]

The exception was thrown inside the foreach statement.

Hang on - you said before that it wasn't getting inside the foreach
statement. You said that "msgs" was empty - which means it wouldn't be
trying to set the value.

Which is it?
After it excute
el.Element("MessageStaus").SetValue(newStatus.ToString());
this line of code, the exception was fired.

After it executed that, or during the execution? My guess is that
el.Element("MessageStaus") is returning null, but you really need to
make sure your diagnostics are consistent before you go any further.
If it *is* going into the foreach loop, work out why you thought it
wasn't.

Then look at "el" (again, with a message box or something similar) to
see whether it really does have a MessageStaus element.

Jon
 
W

Wan

Hang on - you said before that it wasn't getting inside the foreach
statement. You said that "msgs" was empty - which means it wouldn't be
trying to set the value.

Which is it?


After it executed that, or during the execution? My guess is that
el.Element("MessageStaus") is returning null, but you really need to
make sure your diagnostics are consistent before you go any further.
If it *is* going into the foreach loop, work out why you thought it
wasn't.

Then look at "el" (again, with a message box or something similar) to
see whether it really does have a MessageStaus element.

Jon

Hi Jon
Problem is solved. The LINQ statement I wrote was incorrect. Because
in my XML, I have namespace, but I didn't specify it in my XElement.

Thanks very much for your help :)

Best Regards,
Wan
 

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