Issue
I’ve been following this tutorial for Xamarin to make an android application and for some reason the compiler gives this error
Error CS1061 'Resources' does not contain a definition for 'layout' and no accessible extension method 'layout' accepting a first argument of type 'Resources' could be found (are you missing a using directive or an assembly reference?) XamarinHelloWorld
with this code
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace HelloWorld
{
public class MainActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resources.layout.main);
}
}
}
Yet there is a layout folder in Resources
Solution
I believe you have a typo in your code.
Instead of :
namespace HelloWorld
{
public class MainActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(**Resources**.layout.main);
}
}
}
It should be:
namespace HelloWorld
{
public class MainActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(**Resource**.layout.main);
}
}
}
Answered By – tomerpacific