While I create android app in Visual Studio with Xamarin I got strange error - CS0103 The name 'Resource' does not exist in the current context. When I do Clean and then Build, there are no any problems, build is success. But when I changes something in code, Error appears again. I tried to make changes according this post but all file names in Resources folder are ok. Can anybody help me with this problem?
6
- Please post your complete error message.York Shen– York Shen2018-01-05 07:26:29 +00:00Commented Jan 5, 2018 at 7:26
- @YorkShen-MSFT it's in title - CS0103 The name 'Resource' does not exist in the current contextAdeptus Mechanicus– Adeptus Mechanicus2018-01-06 10:03:40 +00:00Commented Jan 6, 2018 at 10:03
- I think we'd likely need to see more information to help you pinpoint the problem. You can add a diagnostic build output to this, that would be really appreciated.York Shen– York Shen2018-01-07 12:05:19 +00:00Commented Jan 7, 2018 at 12:05
- Possibly this known bug: bugzilla.xamarin.com/show_bug.cgi?id=60343dot3dash4dot– dot3dash4dot2018-01-09 12:12:14 +00:00Commented Jan 9, 2018 at 12:12
- @jimmyjudas Nope that's another bugAdeptus Mechanicus– Adeptus Mechanicus2018-01-09 14:19:25 +00:00Commented Jan 9, 2018 at 14:19
| Show 1 more comment
2 Answers
short:
make sure your Namespace is same across all these files that is mentioned below ;
- Resource.Designer.cs
- every Activity that procudes error:"cs103 resource doesnt exist .."
- yourproject.csproj (edit vith notepad)(verify "RootNamespace" ,"AssemblyName" is same with your namespace )
after you make them all same Namespace clean+build should work
long:
if you have changed namespace in anywhere in the project,
you gotta Find And Replace oldNameSpace to NewNameSpace inside yourProjectName.csproj file (open with text editor outside of vs2015 ide)
why ??
when you compile project namespace in the Resource.Designer.cs is overwritten with this values from csproj file
Any Activity:
namespace yourNew_NameSpace // <-- Attention here !!!!!! { [Activity(Label = "asdf", MainLauncher = true )] public class act_main : Activity { TextView tv_camResolution; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.ly_main); tv_camResolution = FindViewById<TextView>(Resource.Id.textView1); } ...... .csproj file :
.... <RootNamespace>OldNameSpace</RootNamespace> <AssemblyName>OldNameSpace</AssemblyName> .... Resource.Designer.cs:
//▼▼▼below see oldnamespace [assembly:global::Android.Runtime.ResourceDesignerAttribute("OldNameSpace.Resource", IsApplication=true)] namespace OldNameSpace // <--- and here see oldnamespace { ....