# .NET XmlValidatingReader

**URL:** <https://boards.straightdope.com/t/net-xmlvalidatingreader/316724>\
**Category:** Factual Questions\
**Created:** [August 12, 2005, 2:09pm UTC](https://boards.straightdope.com/t/net-xmlvalidatingreader/316724 "2005-08-12T14:09:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nature\_s\_Call](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/nature_s_call/32/19006_2.png) [@Nature\_s\_Call](https://boards.straightdope.com/u/Nature_s_Call)\
**Post date:** [August 12, 2005, 2:09pm UTC](https://boards.straightdope.com/t/net-xmlvalidatingreader/316724/1 "2005-08-12T14:09:11Z")

</div>

The following is not PHP code, rather C# (the PHP tags colourize C# pretty nicely, no?) I didn’t write it, but I gotta fix it. (comments, try…catch… other unnecessaries removed for your viewing pleasure)

```php

class Class1
{
  [STAThread]
  static void Main(string[] args)
  {
    XmlDocument doc = new XmlDocument();
    doc.Load(@"c:\doc.xml");

    XmlTextReader textReader = new XmlTextReader(@"c:\schema.xsd");         
    XmlSchema xsd = XmlSchema.Read(textReader, new ValidationEventHandler(XMLValidationErrorHandler));
    textReader.Close();

    XmlValidatingReader mvr = new XmlValidatingReader(doc.OuterXml, XmlNodeType.Document, null);
    mvr.Schemas.Add(xsd);
    mvr.ValidationType = ValidationType.Schema;
    mvr.ValidationEventHandler += new ValidationEventHandler(XMLValidationErrorHandler);

    while(mvr.Read());

    Console.WriteLine("All is well");
    Console.ReadLine();
  }

  static private void XMLValidationErrorHandler (object sender, System.Xml.Schema.ValidationEventArgs e)
  {
    throw new Exception(e.Message);
  }
}

```

My question: Why the hell does this work fine on the developer’s machine but not on our test server?

Details:  
Developer workstations: XP SP2  
Test server: Win2K3

Each has .NET Framework v1.1.4322, (and v1.0.3705) and the app is compiled against v1.1

On the test server, the call to mvr.Read() throws an InvalidOperationException: “The operation is not valid due to the current state of the object.”

The only difference I’ve found: Test server has MSXML v4.20.9818.0 and DevWS has MSXML v4.10.9404.0. There’s a mountain of red tape to make any changes to the Test Server, so before I wade through it to sync the versions: can this be the explanation? We’re not using the MSXML components, but do the .NET classes sit on top of it? (I thought they were ground-up stand-alone?)

---

<div class="post-metadata">

**Author:** ![Ponder\_Stibbons](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ponder_stibbons/32/343_2.png) [@Ponder\_Stibbons](https://boards.straightdope.com/u/Ponder_Stibbons)\
**Post date:** [August 12, 2005, 2:43pm UTC](https://boards.straightdope.com/t/net-xmlvalidatingreader/316724/2 "2005-08-12T14:43:31Z")

</div>

That’s a wierd one alright. The only thing I can think of right off is rights. That is, does the .NET process have the proper rights to the file being read?

Further, if this is an [ASP.NET](http://ASP.NET) application then you must also account for the version of IIS that is running as well as the OS. I’m currently working on an [ASP.NET](http://ASP.NET) app on my work machine that’s running IIS v6 on Windows XP. Our hosted server is running IIS v5 on Win2003. The “user” rights that are required are different for the two machines.

---

<div class="post-metadata">

**Author:** ![Nature\_s\_Call](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/nature_s_call/32/19006_2.png) [@Nature\_s\_Call](https://boards.straightdope.com/u/Nature_s_Call)\
**Post date:** [August 12, 2005, 2:58pm UTC](https://boards.straightdope.com/t/net-xmlvalidatingreader/316724/3 "2005-08-12T14:58:27Z")

</div>

> [@Ponder Stibbons](#):
>
> That’s a wierd one alright. The only thing I can think of right off is rights. That is, does the .NET process have the proper rights to the file being read?
> 
> Further, if this is an [ASP.NET](http://ASP.NET) application then you must also account for the version of IIS that is running as well as the OS. I’m currently working on an [ASP.NET](http://ASP.NET) app on my work machine that’s running IIS v6 on Windows XP. Our hosted server is running IIS v5 on Win2003. The “user” rights that are required are different for the two machines.

Rights/permission was high on my list too. The acutal system has a highly complex architechture (Web Service calls BizTalk orchestration, calls a series of components, SQL Server, Oracle, blah blah blah). Multiple services, running as multiple users, Windows ACL, database ACLs, yada yada yada.

To avoid the clutter, I excerpted the above logic into the teeny console app above. This reproduces the behaviour without all the hassle. The app runs as the user logged on - Administrator privileges in both cases, with Full control on all files/folders. By denying rights, the exception thrown is “Access denied.”

---

<div class="post-metadata">

**Author:** ![Nature\_s\_Call](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/nature_s_call/32/19006_2.png) [@Nature\_s\_Call](https://boards.straightdope.com/u/Nature_s_Call)\
**Post date:** [August 12, 2005, 4:04pm UTC](https://boards.straightdope.com/t/net-xmlvalidatingreader/316724/4 "2005-08-12T16:04:05Z")

</div>

I changed while (messageValidatingReader.Read()) to the following

```php

int count = 0;
while (messageValidatingReader.Read())
{
  Console.WriteLine("Successfully read {0} times", ++count);
}

```

On the dev box it runs successfully 124 times. On the Test Server only 3 (failing on the fourth read, I presume).

Further: A developer has recently left. To avoid changing my machine, I’ve am using his as an experimental (change the MSXML, for e.g.)

BUT, turns out although his machine is XP SP2 as is mine, his version of MSXML is the same as the Server’s. AND the above test app behaves the same way as it does on the server.

HOWEVER, I ran procexp, as well as removed MSXML altogether - both confirm the MSXML version is a red herring.

FINALLY, when I first got on his machine I was not an administrator. The app failed. I had tech upgrade me to administrator. The app still failed.

Arrgghhh… (I’m getting ready to Pit Microsoft!)

---

<div class="post-metadata">

**Author:** ![Nature\_s\_Call](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/nature_s_call/32/19006_2.png) [@Nature\_s\_Call](https://boards.straightdope.com/u/Nature_s_Call)\
**Post date:** [August 12, 2005, 6:44pm UTC](https://boards.straightdope.com/t/net-xmlvalidatingreader/316724/5 "2005-08-12T18:44:53Z")

</div>

For those who may be interested: Found the problem. Our BizTalk development team were the first to receive a number of .NET framework hotfixes. Tech upgraded only our dev boxes, but hadn’t yet swam through the red tape to apply them to the servers (nor told the dev team about any of this).

[This](http://support.microsoft.com/?kbid=842832) is the specific problem solved by one of the hotfixes.

Thanks **Ponder Stibbons** for your time, and for anyone else who may have mulled over the problem.
