user3548779
user3548779

Reputation: 321

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

In Xamarin, I have pasted the following code from a working activity into a blank new activity:

[Activity (Label = "SimpleOnePageViewPager", MainLauncher = true)]
public class MainActivity : FragmentActivity
{
    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        SetContentView (Resource.Layout.Main);

        FragmentItem fragItem = new FragmentItem ();

        List<Android.Support.V4.App.Fragment> fragments = new List<Android.Support.V4.App.Fragment>();
        fragments.Add(fragItem);

        ViewPagerAdapter pageAdapter = new ViewPagerAdapter(SupportFragmentManager, fragments);
        var pager = FindViewById<ViewPager>(Resource.Id.MainViewPager);
        pager.Adapter = pageAdapter;
    }
}

This is the error that I am getting?

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

Can I please have some help with this code?

Thanks in advance

Upvotes: 1

Views: 8650

Answers (5)

Nhan Phan
Nhan Phan

Reputation: 1302

I met same problem today. I searched around, and also tried above solutions, but it did not work from my side. I already resolved the problem by myself with bellow steps:

  1. Update xamarin nuget packages
  2. Clean and rebuild the project

P/S: hope it can help others if they meet same problem.

Happy coding!

Upvotes: 0

Anderson
Anderson

Reputation: 11

I had this problem too, and solved with this steps:

Open MainActivity.cs of the Android project and put the line:

using AppName.Droid

This line is the name of namespace in the file Resource.designer.cs

Upvotes: 1

BlueCompany
BlueCompany

Reputation: 72

Make sure you added namespace using Project_Name;

Upvotes: 1

Caio
Caio

Reputation: 61

It was exactly the problem that I just solved, I think that this is a Xamarin Bug, when you add an existing xaml file it add it to the project without set it as embedded resource as it should be, and without set the custom tool command that must be set to: MSBuild:UpdateDesignTimeXaml

Upvotes: 0

Immanuel Kirubaharan
Immanuel Kirubaharan

Reputation: 1094

You can change the MainActivity.cs Build Action property as 'none' instead of 'compile'. I Hope this will resolve your problem.

Thanks, Imman

Upvotes: 0

Related Questions