If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: XMLReader not working

Originally Posted by SamiH

All I get is an error: "Object reference not set to an instance of an object. The stacktrace points at the Read()-operation.

Unless this exception gets thrown as a result of an internal error in XmlTextReader::Read(), which I consider to be rather unlikely, it seems to indicate either of two things: XmlTextReader::Create() returned nullptr or it returned something that couldn't be legally cast into an XmlTextReader ^. (If you had used a safe_cast instead of the dynamic_cast, these two scenarios would have led to different exceptions. That's one of the things I really learned to appreciate about the safe_cast.) Given the name of the static method and the class it's a member of, the latter seems to be rather unlikely, and as of now I didn't research any potential reasons for the former. Whether reader actually is nullptr at the point where the exception gets thrown can easily be verified by debugging.

Re: XMLReader not working

Thanks for the reply!

I broke down the errorhandling, and found out that it was the cast from XmlTextReader::Create(stm) that did not return an XmlTextReader, but another class inheriting from XmlReader. Just assigning it to a XmlReader pointer solved the problem!

Kind of off-topic, but since you seem to be a wiz, would you have any idea about this problem:

The program above works if I input an address to a XML-file. But if the address is to a server, which would have returned a XML-file if I pasted it into a web browser, this doesn't seem to work. For example:

Re: XMLReader not working

Originally Posted by SamiH

I broke down the errorhandling, and found out that it was the cast from XmlTextReader::Create(stm) that did not return an XmlTextReader, but another class inheriting from XmlReader. Just assigning it to a XmlReader pointer solved the problem!

Ah, I see. Checking that on MSDN I found that XmlTextReader doesn't even have a Create() method, it just inherits one (or more exact: a dozen overloads of it) from XmlReader, and AFAICT (only had a closer look on the one you were calling) they all return an XmlReader that, despite the inheritance relation, can't be cast into an XmlTextReader. (A cast in the other direction would work, however.)

[...] But if the address is to a server, which would have returned a XML-file if I pasted it into a web browser, this doesn't seem to work. For example:

To me that looks like an HTTP protocol error, and unfortunately that's an area I'm not a wiz on. At any rate, at least my IE8 (executed as secure browser under Kaspersky Security Suite) isn't able to open that URL either.

I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.