I am building an Android App in Visual Studio. When I try to build the app referencing items in the Resources folder, I get one of two errors.
If I preface "Resource.Layout.[Id]" or "Resource.Id.[Id]" with the namespace for my project, I get this error:
The type or namespace name 'Resource' does not exist in the namespace '[app namespace]' (are you missing an assembly reference?)
If I don't preface the call to Resource with my namespace, it tries to access the default Android.Resource class and I get this error:
'Android.Resource.Layout' does not contain a definition for '[axml file]'
Has anyone run across this error before? I've been searching for a while and cannot come up with anything that seems to be wrong. The Resource.Designer file exists. I've deleted it and let it get regenerated. The Ids are in the Resource file, the project just doesn't recognize that the resource class is there at all.
Originally, the namespace for this application ended in "Android". Thinking that may be part of the issue, I've changed it to "_Android" and "AndroidApp", including changing the default namespace in the project properties and changing the namespace declaration in each file. However, this error persists through each change.
5条答案
按热度按时间jdzmm42g1#
当你添加一个新文件,而Visual studio将其设置为错误的构建操作时,可能会发生这种情况。我知道这种情况我已经发生过很多次了,我可能会花很长时间试图弄清楚发生了什么。如果你右键单击该文件并看到构建操作,这应该设置为Android资源。希望它能有所帮助
goucqfw62#
代码中的命名空间和解决方案资源管理器中的命名空间应该相同。
smtd7mpg3#
唯一对我有用的是关闭VS,完全删除项目的所有
bin
和obj
文件夹,重新打开它,然后重新编译所有内容。这是由于在Visual Studio Mac上工作,然后在Windows计算机上打开同一个项目时出现了一些问题。6jjcrrmo4#
在AndroidManifest.xml中,确保没有依赖于其他资源的名称,这些名称对于Ex:
xggvc2p65#
我遇到了这个问题,我解决它很简单:
1-清理启动项目
2-为android再造一次。
就这样了