A namespace does not directly contain members such as fields or methods

A namespace does not directly contain members such as fields or methods – another interesting and completely unhelpful error message courtesy of .Net.  Thankyou for flying 😉

This particular error caused me a great deal of problem in a piece of software I had designed and written that used Web Services Enhancements (WSE) 2.0 SP3, using Visual Studio .Net 2003.  There wasn’t a lot of information around but I eventually solved the problem – actually, it was quite simple.

 As anyone using web services enhancements knows, you right click the project name, choose “Web Service Enhancements” and check the little check box to enable WSE for your project.  This adds an app.config to your program if you dont already have one with a little configuration information designed to make WSE work for you.

 Turns out if your app.config gets invalid somehow, that can cause this error to occur.  I had two things in my app config, both managed by the designer – the wse settings and a dynamic web service link.  The fix was simple, I set the web service link back to static (to remove its dependancy on the app.config) and disabled wse 2.0.  Then I hit compile.  It wont compile of course, without the WSE addons it needs, but I figure it’d ensure that the changes I made had propogated.  I then deleted the app.config file altogether and re-enabled wse 2.0.

This creates a new app.config with the appropriate settings, and whatever was corrupted about my old one was now corrected.  All I had to do then was reset my web service link to dynamic, update the reference and hit recompile and it worked like a charm.

So just remember a possible reason for this error can be a corrupted app.config.  Regenerate it (or re-write it if you manually wrote the file) and it can vanish nice and easy.

Advertisements

One thought on “A namespace does not directly contain members such as fields or methods

  1. Thanks! I saw the same problem today & was able to correct it simply by deleting my old AppConfig and creating a new one.

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