Error “A namespace does not directly contain membe

2019-01-11 21:37发布

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?

8条回答
孤傲高冷的网名
2楼-- · 2019-01-11 21:54

I managed to reproduce the error.

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

查看更多
地球回转人心会变
3楼-- · 2019-01-11 21:54

I had the same error. Checked if the app.config was set to none, no problems there. After 30 minutes of checking and rechecking, I restarted VS and that did the thing. It usually solves 90% of the unlogical errors. Sighs.

查看更多
smile是对你的礼貌
4楼-- · 2019-01-11 22:02

I solved this way: right click on .axml file -> Build Action ->AndroidResource (xamarin studio)

查看更多
Bombasti
5楼-- · 2019-01-11 22:04

I was facing this same issue with XML file. This was due to .net compiler tried to compile this xml which has been used only for DATA purpose hence no need of compilation.

Fix : Go to property of this file and change the Build Action to content from compile.

Thanks

查看更多
劳资没心,怎么记你
6楼-- · 2019-01-11 22:06

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.

查看更多
劳资没心,怎么记你
7楼-- · 2019-01-11 22:06

I was having a similar problem with the code behind in my website. The issue turned out to be an extra closing bracket that caused my class to end right after page_load(). Always check for silly syntax errors like this one.

查看更多
登录 后发表回答