the name resources does not exist in the current context Xamarin

本秂侑毒 提交于 2019-12-20 00:59:10

问题


public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);
            EditText val1 = FindViewById<EditText>(Resource.Id.txtuser1);
            EditText val2 = FindViewById<EditText>(Resource.Id.txtuser2);

Error :

The name 'Resource' does not exist in the current context.


回答1:


I was so resolved (by visual studio)

  1. Remove 3 line

    SetContentView(Resource.Layout.Main);
    EditText val1 = FindViewById<EditText>(Resource.Id.txtuser1);
    EditText val2 = FindViewById<EditText>(Resource.Id.txtuser2);
    
  2. Build -> Clean

  3. Build -> Rebuild
  4. rewrite remove 3 line



回答2:


Following steps work for me

  • Copy resource folder on desktop
  • I successfully deleted the Resources folder from the project. I cleaned the solution then I closed the project and I restarted VS.
  • I copied a copy of the same folder into the project tree and I included it again in the project.



回答3:


Add your Diagnostic Build Logs : https://forums.xamarin.com/discussion/27515/how-to-obtain-diagnostic-build-logs

Meanwhile, take a look at this link : https://forums.xamarin.com/discussion/5261/the-name-resource-does-not-exist-in-the-current-context




回答4:


I was facing the same issue today in my Xamarin application. I tried the following things

  1. Clean the solution and rebuild
  2. Close Visual Studio and open again
  3. Delete the obj and bin folder and rebuild the project

None of the above things worked for me. The real issue was because of that the file Resource.Designer.cs was excluded from my project and including that to the solution fixed the issue for me.

Hope it helps



来源:https://stackoverflow.com/questions/37517264/the-name-resources-does-not-exist-in-the-current-context-xamarin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!