Visual Studio 2010 XML Schema Errors–xsd:import


Introduction

I’ve been looking at the option for a Publish and Subscribe web service model for a development project which is starting up at work. The research into the Publish and Subscribe model has had me looking at closely at the WS-BaseNotification specification.

To take a closer look at the standard, and what would be involved in implementing this for the project I downloaded the xml schemas (XSD’s) and web service definition language (WSDL) files for the standard. These files I then loaded up into Visual Studio 2010, and that’s when the “fun started”. These files were including (xsd:import) schemas from over the web, and Visual Studio was getting errors doing this. After a quick browse on the internet, it seemed like a common problem, with some complex solutions.  So, thinking there must be a better way, I started solving the problem, my way.

The Errors

Warning          2          Request for the permission of type ‘System.Net.WebPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.

Warning          3          Request for the permission of type ‘System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.

The “Fix”

I have found that the simplest way to solve these types of errors is to do the following:

  • Download the xsd file being referenced.
    • Paste the URL into IE and get the xsd file up in the browser.
    • Use File –> Save As. To save a copy of the xsd file into the Visual Studio project directory which you are keeping your source code in.
  • Add the xsd file you just downloaded to the project, and open the xml editor for that file.
  • Right click the editor tab for file you just downloaded, and select the “Copy Full Path”.
  • Then change the xsd:import from:
  <xsd:import namespace="http://www.w3.org/2005/08/addressing"
    schemaLocation="http://www.w3.org/2005/08/addressing/ws-addr.xsd"
  />

To

  <xsd:import namespace="http://www.w3.org/2005/08/addressing"
    schemaLocation="file://visual studio 2010/Projects/Project1/DummyShell/ws-addr.xsd"
  />

  • Tip: You have the file location in the clipboard from the “Copy Full Path”, so you only need to swap the \’s to /’s.
  • This makes the reference to a local copy of the schema file.

I’ve had situations where Visual Studio still gives the System.Security.Permissions.FileIOPermission exception/error after making this change. Restarting Visual Studio seemed to “clean out” the error and everything was fine after the restart.

Conclusion

Importing schemas into other schemas is a very powerful feature of xml schema language, but a real pain with Visual Studio. I’m not sure why things get so difficult, the schema cache which Visual Studio maintains seems to, in part, cause extra confusion. This approach ignores the schema cache altogether. Although I did “copy” the xml schema (xml.xsd) from the cache, into the project as well (one of the consequential dependencies required it).

Advertisements

, , , , , , ,

  1. #1 by Simona Colapicchioni on August 31, 2011 - 8:00 pm

    http://msdn.microsoft.com/en-us/library/ms255819.aspx
    If I understand correctly, it looks like it is “by design”.

    • #2 by aussiecraig on September 3, 2011 - 7:23 pm

      Thanks for the pointer to the MSDN page.

      It just reminds me of how much I hate the XmlShemaSet class http://msdn.microsoft.com/en-us/library/system.xml.schema.xmlschemaset.aspx .
      It all go to an observation: ‘There must be an easier way!’
      Makes me think I should some extension methods for the Schema Set Class which parses the XML and hooks up the schema references. But, that will not fix the schema and WSDL problems.

      Craig

  2. #3 by kimberly on February 20, 2011 - 2:21 pm

    your good

    • #4 by aussiecraig on February 20, 2011 - 6:41 pm

      Thanks,
      There is a lots of “How do I fix this?”, “Try this – didn’t work”, “Try that – didn’t work”, before I find the answer.
      When I do find “good” answers, then I post them.
      To quote Thomas Alva Edison:

      “Genius is 1% inspiration and 99% perspiration!”

      Craig

  3. #5 by interior design on February 18, 2011 - 8:35 am

    It’s very exiting to find your craigwatson1962.wordpress.com site.
    What a neat blog! I love how particular each of the entries are. They are well balanced, both informational and amusing, and the pictures are nice too.

    • #6 by aussiecraig on February 18, 2011 - 4:41 pm

      Thanks,
      I keep trying to make this blog informative, and entertaining.

      Craig

  4. #7 by zee on February 7, 2011 - 10:41 pm

    Nice info and post! Thanks!
    zee

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: