从https://stackoverflow.com/a/36409069
有一个长期的调试问题Xamarin.Android与Visual Studio相关的静态类检测值。具体而言,如果您在引用静态类(或具有静态成员的非静态类)的行上设置断点,则Visual Studio可能会将检查值显示为“未知标识符:[ClassName]”。
从我的分析中可以看出,项目中类文件的位置决定了你是否会遇到这个问题。
对我而言,最终结果是,除非Xamarin修复了这个错误,否则所有静态类和具有静态成员的类都应放置在项目的根文件夹中。还有其他的文件放置选项,但某些单元不起作用,并且需要用命名空间完全限定静态类调用 - 即使编译器不需要。
有关完整的详细信息,请参阅下面的代码中的注释。
MainActivity.cs
using System;
using Android.App;
using Android.OS;
namespace App1 {
[Activity(Label = "Unknown Identifier Test", MainLauncher = true)]
public class MainActivity : Activity {
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
Console.WriteLine(MyClass.MyString); // Unqualified
Console.WriteLine(App1.MyClass.MyString); // Fully Qualified with namespace
/*
Set a break point on the "Console.WriteLine()" lines above and you'll get the
"Unknown identifier: MyClass" error when trying to inspect under specific conditions...
File Locations Unqualified Fully Qualified
------------------------------------------------- --------------------- --------------------
MainActivity.cs in root, MyClass.cs in sub-folder "Unknown identifier" Inspection Works
MainActivity.cs in sub-folder, MyClass.cs in root Inspection Works Inspection Works
Both in root Inspection Works Inspection Works
Both in different sub-folders "Unknown identifier" "Unknown identifier"
Both in same sub-folder "Unknown identifier" "Unknown identifier"
*/
}
}
}
MyClass.cs
namespace App1 {
public static class MyClass {
public static string MyString;
}
// The class can also be constructed this way, which results in the same findings:
//public class MyClass {
// public static string MyString;
//}
}
在2016年4月3日,我更新了相关Xamarin的Bugzilla票这一信息。希望他们很快得到解决。
检查'Resources/layout'中是否有'grid_item.xml'文件。你有没有尝试清洁项目? –
查看你的android资源。确保它们设置为AndroidAsset而不是AndroidBundle? –