從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? –