0

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. Commented Jan 5, 2018 at 7:26
  • @YorkShen-MSFT it's in title - CS0103 The name 'Resource' does not exist in the current context Commented 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. Commented Jan 7, 2018 at 12:05
  • Possibly this known bug: bugzilla.xamarin.com/show_bug.cgi?id=60343 Commented Jan 9, 2018 at 12:12
  • @jimmyjudas Nope that's another bug Commented Jan 9, 2018 at 14:19

2 Answers 2

1

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 { .... 
Sign up to request clarification or add additional context in comments.

Comments

0

I have the same error, but my code compile. so its maybe related to the wrong import or ambiguous Resources object. Note that there is Resources and Resource i believe Resources is coming from android sdk.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.