views:

772

answers:

3

I'm trying to build my C# project and I'm getting the error message "A namespace does not directly contain members such as fields or methods". It is flagging the first character (the less than symbol) of the app.config file.

I've checked all of my files for places where there are variables or functions directly inside of a namespace--found nothing. The app.config looks fine.

Google is failing me and I'm pulling my hair out. What could be causing this error?

A: 

This error occurs when you attempt to add a field or member directly into a namespace. Given it's pointing to app.config it's likely that VS is in a bad state. Try closing and reopening Visual Studio and see if the error goes away.

Failing that try rebuilding and posting the results from the build output window to your question.

JaredPar
+3  A: 

Figures! As soon as I finally break down and ask the question that I find the answer...

The app.config file properties section (somehow) listed the Build Action of "Compile" when it should be set to "None".

How in the world did it get changed? I know I didn't change it. Grrr...

Oh well, at least it's building now. Hopefully someone else will benefit from my hairloss.

BoltBait
Hah, called it.
Anon.
Yes you did. Now, where were you yesterday?!
BoltBait
Tearing my hair out over some other silly issue. Most of these lessons are ones learned from firsthand experience :/
Anon.
A: 

I managed to reproduce the error.

Check the properties for the app.config file. The Build Action should be None, not Compile.

Guffa