Adeptus Mechanicus
Adeptus Mechanicus

Reputation: 171

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

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?

Upvotes: 0

Views: 7329

Answers (2)

bh_earth0
bh_earth0

Reputation: 2818

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  
{

    ....

Upvotes: 1

Hicham Bagui
Hicham Bagui

Reputation: 240

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.

Upvotes: 0

Related Questions