Home » Android » c# – Resource.Id not working in Xamarin

c# – Resource.Id not working in Xamarin

Posted by: admin May 14, 2020 Leave a comment


This is main.axml file.

`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/myListView" />

And this is the MainActivity.cs file :

protected override void OnCreate(Bundle bundle)

    // Set our view from the "main" layout resource

    Glop = new List<string>();


    Name = FindViewById<ListView>(Resource.Id.myListView);


I am trying to create a Listview in Xamarin Android.

I have changed the android Id to myListView and also have tried to rebuild the app but it still shows as an error . What should I do now ?

How to&Answers:

Try rebuilding the app again and saving the main.axml file .

  • Build > Clean Solution

  • Build Solution


For Visual Studio Community 2019 Preview (V 16.0.0, Pr 5.0):

For this problem and a lot of the problem with the designer I have to repeatedly do the following:

  • Save all documents and close VS.
  • Navigate to the project folder in your file browser
  • Delete (or rename, if you’re paranoid) the “obj” and “bin” folders
  • Relaunch VS and try the designer again.

With this version (granted, it’s still beta) running a clean on the project with the designer open will cause access permission errors that can be corrected with these steps.


Adjust properties for resource file like here:

enter image description here


1)Build -> Clean Solution

2)Build Solution


Option 1) Make sure update the Xamarin.Android (Tools>Options>Xamarin>Other>Check Now)

Option 2) Run VS as Administrator and Build>Clean and Rebuild the solution.

For my case option 1 did work. enter image description here


I faced this kind of problem. The cause may be from the duplicate resource IDs in the project. For instance, this problem occurs when you copy a layout file (.axml) and simply paste directly into the layout resource folder in the solution explorer pane without meticulous resource ID name review in it.

Since the ID reference rule in the project’s namespace is to be unique. While the resource ID is auto-generating in the .Designer file, The VS couldn’t determine which one is the right one you intend to use, so all cases of the same resource IDs may be skipped and unprocessed without warning.

The result is – after I made a duplicate layout file in the same project, later I couldn’t reference resource name or ID of them while I’m coding.

The solution for me is to look for the duplicate IDs name in the project and correct them to be unique.