XML namespace prefix 'xmlns' is not defined

Posted Sun, Nov 25 2007 0:58 by bill

When working with VB9 you may get this cryptic error :
XML namespace prefix 'xmlns' is not defined

If you are using only default namespaces you can fix this by including a definition for the xmlns as an Import statement or as an xmlns attribute on the XML literal.  But if you are using prefixed namespaces imported at file level, then you must add an imports at project level via the project properties reference tab.

You have two choices:

  • Import System.Xml.Linq for the entire project, or
  • Import a namespace for the entire project

If you decide to import a namespace it can be any namespace at all.  I named one _do_not_use.  Problem is it will show up in XML axis properties in intellisense, but with a name like _do_not_use, that isn't really a big problem. Of course you could add one that you might want to use.

 

imports

 

You may prefer to simply import System.Xml.Linq, but I thought I'd at least throw all the alternatives out there for you to decide what suits you best.

hopefully this is another bug that will make it into 2008 SP1 ;)

Filed under: , , , ,

Comments

# re: XML namespace prefix 'xmlns' is not defined

Saturday, November 24, 2007 9:41 AM by Avner

Hi Bill,

Can you please post the steps to reproduce this behavior? I would like to open a bug about it (if needed)

Thanks,

Avner

# re: XML namespace prefix 'xmlns' is not defined

Saturday, November 24, 2007 10:16 AM by bill

Hey Avner,

Well the steps are not doing any of the options I outlined above ;)

IOW: if you have no project level Imports for xml namespaces and do not have System.Xml.Linq imported at *project* level (class level makes no difference), then you will get this bug.

# re: XML namespace prefix 'xmlns' is not defined

Saturday, November 24, 2007 10:38 AM by Kathleen

I've repro'd this bug...

1) Create this code in a console app (no file imports):

  Sub Main()

     Dim el = <foo>bar</foo>

     System.Console.Read()

  End Sub

2) Compile to see that all is well

3) Remove the project level import for

4) Compile to see the compile error

Bill has workarounds in the original post.

# re: XML namespace prefix 'xmlns' is not defined

Saturday, November 24, 2007 10:42 AM by Avner Aharoni

Sorry Bill, I still can not repro it, this is what I did, I created a new project and remove the project level Imports to System.Xml.Linq and I do not see any error. Can you be more specific in the repro steps?

Thanks much,

Avner

# re: XML namespace prefix 'xmlns' is not defined

Saturday, November 24, 2007 10:49 AM by bill

Ah, it seems it is *ANY* project level imports.

You must have zero for the bug. Any project level Import will fix the error.

# re: XML namespace prefix 'xmlns' is not defined

Saturday, November 24, 2007 11:16 AM by Avner Aharoni

Thanks Bill, now I can repro it, I will log this bug and we will look to fix it in SP1. Thanks much for your help in finding these bugs, this really helps increase our quality.

Regards,

Avner

# re: XML namespace prefix 'xmlns' is not defined

Saturday, November 24, 2007 5:42 PM by bill

Thanks Avner :)

# simply24 &raquo; Blog Archive &raquo; XML namespace prefix &#39;xmlns&#39; is not defined

Pingback from  simply24  &raquo; Blog Archive   &raquo; XML namespace prefix &#39;xmlns&#39; is not defined