zaterdag 1 april 2006

.NET 2.0: Could not find schema information for ... part 2

Today, I've been playing a bit with the new Configuration classes in .NET 2.0.
Again, I came across those annoying 'Could not find schema-information for ... ' messages.
I do not like warnings and information messages in my projects, so I had the urge to solve these issues.

I was playing a bit with the 'Settings' class in a Windows Forms application. I added a user-scope setting, and I received this warning from Visual Studio.NET 2005:

The requirePermission attribute is not declared

After some crawling on the web, I've found an article written by Peter Richie. It appears to be a negligency from Microsoft: it seems that the DotNetConfig.xsd schema-file is not complete. Peter Richie has adapted this XSD file, so you can download this file and replace the original file with his one. By doing so, I got rid of this error.
Click here for Peter's article.
I can't understand how Microsoft could be so sloppy to not deliver a correct xsd.

Then, I was still annoyed by some 'Information messages' Visual Studio gave me. These were due to a custom configuration section for NHibernate I have in my app.config file.
This is a snippet from my App.Config file:

<section name="nhibernate"
<add key="hibernate.connection.provider"

The 'information message' here told my that a schema definition for the element nhibernate couldn't be found. Off-course, this is not an error, but... I find those things annoying.

So, to get rid of those messages, I've created a simple XSD that describes this 'nhibernate' section. (You can download this XSD here). I've copied this xsd to the Program Files\Microsoft Visual Studio 8\Xml\Schemas\ directory. The next step I had to do, was to include this schema in the DotNetConfig.xsd file.
So, in the same directory, edit the DotNetConfig.xsd file and add this line:

<xs:include schemaLocation="nhibernate_configuration.xsd"/>

If you have a rather complex custom Configuration Section in your App.Config file, you can create your own XSD for it.
You're not only going to get rid of those 'could not find schema information...' messages, but you'll also have Intellisense for your custom configuration section in VS.NET 2005 as well!

Click here for my first post about this problem.

10 opmerkingen:

nick zei

Saai rot blog

Jarno Peschier zei

This is not a comment on this entry, but a notification that I replied to your comment on my MSN Space about the downloadable code from .NET Magazine #12:!FEC8DE0C9895E736!867.entry

Anoniem zei

This page is difficult to read due to Google ads covering your text on the top left.

Frederik Gheysels zei

I'll try to have a look for that as soon as possible.

Anoniem zei

Hi There,

Nhibernate the latest version comes with the XSD to define the configuration elements. I'm just not sure how you add the refrence to the web.config any ideas?

Frederik Gheysels zei


Are you talking about the nhibernate-configuration-2.0.xsd, nhibernate-mapping-2.0.xsd, etc... ?

If so, you just have to copy them to the Program Files\Microsoft Visual Studio 8\Xml\Schemas directory. (If you use VS.NET 2005).

SMHMayboudi zei

eino zei

It works but I had to add include as a second line right after <?xml...> line to get it work with VS Studio 2005 (fix pack 1)

David Gray zei

I encountered the same problem, and installed the amended .xsd file, as you discussed. Initially, there was no change. Eventually, it occurred to me to restart Visual Studio. When I did that, and rebuilt the project, the errors vanished.

Neither your article, nor the one by Peter Richie, to which you refer, mentions that you must restart Visual Studio for the updated schema to take effect.

Frederik Gheysels zei

Sorry, I'll modify the text later today.

In either way, when you copy a new XSD file to the Xml/Schema directory in the VS.NET folder, you always have to restart VS.NET before VS.NET can use this XSD to provide intellisense.
(For instance, if you want to use NHibernate, and you want to have intellisense for your mapping files, you have to copy the nhibernate-mapping.xsd file to the xml/schemas directory.
You will not have intellisense support for NHibernate mappings until you restart VS.NET).