locked
AXML & C# - Resources does not contains a definition for '' RRS feed

  • Question

  • User211233 posted

    I'm coming, one more time, after deep search on google and as usual, I can't find the answer which can solves my problem...

    I have these 3 errors:

    Error   CS0117  'Resource.Layout' does not contain a definition for 'NativeAndroidCell'
    Error   CS0117  'Resource.Id' does not contain a definition for 'Ride'  Project.Droid
    Error   CS0117  'Resource.Id' does not contain a definition for 'Since' Project.Droid
    

    from this c# code

    public class NativeAndroidCellRenderer : ViewCellRenderer
    {
        protected override Android.Views.View GetCellCore(Xamarin.Forms.Cell item, Android.Views.View convertView, ViewGroup parent, Context context)
        {
            var x = (NativeCell)item;
    
            var view = convertView;
    
            if (view == null)
            {
                // no view to re-use, create new
                view = (context as Activity).LayoutInflater.Inflate(Android.Resource.Layout.NativeAndroidCell, null); //'Resource.Layout' does not contain a definition for 'NativeAndroidCell'
            }
    
            view.FindViewById<TextView>(Android.Resource.Id.Ride).Text = x.Ride; //'Resource.Id' does not contain a definition for 'Ride'
            view.FindViewById<TextView>(Android.Resource.Id.Since).Text = x.Since; //'Resource.Id' does not contain a definition for 'Since'    
    
            return view;
        }
    }
    

    So, I saw that it can comes from the build action so I set it to AndroidResource

    The content is the following:

        <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:orientation="vertical"
                android:padding="10dp"
                android:background="#FFFFFF">
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#FF0000"
                    android:gravity="center">
                    <TextView
                        android:id="@+id/Ride"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"
                        android:text="Caen - Narbonne"
                        android:textColor="#FFFFFF"
                        android:textSize="30dp" />
                    <TextView
                        android:id="@+id/Since"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:gravity="center_vertical"
                        android:text="6mins."
                        android:textColor="#FFFFFF" />
                </RelativeLayout>
                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#FFFFFF">
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_alignParentLeft="true"
                        android:orientation="horizontal"
                        android:gravity="center_vertical">
                        <TextView
                            android:id="@+id/Duration"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="19mins"
                            android:textColor="#000000"
                            android:layout_weight="0"
                            android:padding="5dp" />
                        <TextView
                            android:id="@+id/Pseudo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="Emixam23"
                            android:textColor="#000000"
                            android:layout_weight="0"
                            android:padding="5dp" />
                        <TextView
                            android:id="@+id/StopNumber"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="1 arret"
                            android:textColor="#000000"
                            android:layout_weight="0"
                            android:padding="5dp" />
                    </LinearLayout>
                    <Button
                        android:id="@+id/More"
                        android:layout_width="45dp"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="true"
                        android:text="+" />
                    <Button
                        android:id="@+id/Agree"
                        android:layout_width="45dp"
                        android:layout_height="wrap_content"
                        android:layout_alignParentEnd="true"
                        android:layout_alignParentRight="true"
                        android:layout_alignParentTop="true"
                        android:text="V" />
                </RelativeLayout>
            </LinearLayout>
        </RelativeLayout>
    

    As you can see, this NativeAndroidCell.axml seems all right, so what is happening? my Resource.Designer.cs has a build action of Compile

    I'm juste trying to follow the tutorial of Customizing a ViewCell

    If anyone can help, thank !

    Friday, June 10, 2016 12:03 AM

Answers

  • User211233 posted

    @BijayBudhathoki hey !

    I found a solution, maybe it's not the thing that solves it, maybe yes, but if (from the Android SDK manager sandlone) you have the last version etc of the packages Android, then update the Android nugget that you have (they should be 23.3.0 something like that, update them to the last version so everything will match and then, it'll work. Before try that on your project, test from another solution :)

    Best,

    Max

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, July 12, 2017 2:15 PM
  • User211233 posted

    Yep, I mean, I think so..

    You want the last update of the nuget package for android? Then update your android lib from the Android SDK Manager.

    I think if you want the last update, you need Android 8, but you have to try and confirm ;)

    Best,

    Max

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, September 11, 2017 10:34 PM

All replies

  • User76916 posted

    @Emixam23 - Just as a first port of call, try deleting everything inside the Resource.Designer.cs file. Then rebuild your application. I find the Resource.Designer.cs doesn't rebuild nearly as often as it should and you need to wipe it out before it rebuilds again.

    Friday, June 10, 2016 2:07 AM
  • User211233 posted

    I'm again on that problem today haha, so weird because I deleted it and nothing changed, it doesn't recreate it anyway

    Monday, July 3, 2017 7:15 PM
  • User321342 posted

    I am also in same problem there is no ID property in Resource class ex ...FindViewById

    Wednesday, July 12, 2017 12:01 PM
  • User211233 posted

    @BijayBudhathoki hey !

    I found a solution, maybe it's not the thing that solves it, maybe yes, but if (from the Android SDK manager sandlone) you have the last version etc of the packages Android, then update the Android nugget that you have (they should be 23.3.0 something like that, update them to the last version so everything will match and then, it'll work. Before try that on your project, test from another solution :)

    Best,

    Max

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, July 12, 2017 2:15 PM
  • User340929 posted

    Great tip. I've been trying to solve this problem for a long time. Thank you!

    Monday, August 7, 2017 7:27 PM
  • User347566 posted

    Did anyone get any solution for this? Also having the same problem and I didn't have any luck from updating the android nugget. Thanks guys

    Monday, September 11, 2017 5:59 AM
  • User211233 posted

    Yep, I mean, I think so..

    You want the last update of the nuget package for android? Then update your android lib from the Android SDK Manager.

    I think if you want the last update, you need Android 8, but you have to try and confirm ;)

    Best,

    Max

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, September 11, 2017 10:34 PM
  • User361715 posted

    The best and easy solution is clear the Main.axml page and Reset and it is working. B) B) B) B)

    Monday, December 4, 2017 9:07 AM
  • User364448 posted

    In my case, I was receiving resource related errors, but my solution itself would still compile. It's still annoying though to have the error list littered with false errors. It seems something in the .vs folder within my solution must have become corrupt. None of the other recommendations I tried were successful, but once I deleted the .vs folder, cleaned my solution and then re-opened studio, I no longer received the false errors. I would recommend trying this for anyone who has a similar situation.

    Wednesday, January 10, 2018 8:02 PM
  • User360406 posted

    I also copy-pasted code from another project into an *.axml layout file, and got this error. Here's what solved it for me: I simply added a new Button in the *.axml file, saved it, built it, and it worked. Afterwards I removed the Button, and it still worked. Not sure what causes this, but my guess is that inside the Resource.Designer.cs file you see this Attribute on the class: [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] And it seems that the way the compiler interprets this is that a copy-paste doesn't qualify as file modification, but if you actually edit it with the cursor and type, then that does. ¯\(?)

    Sunday, June 3, 2018 11:50 AM
  • User345002 posted

    @AdamP said: @Emixam23 - Just as a first port of call, try deleting everything inside the Resource.Designer.cs file. Then rebuild your application. I find the Resource.Designer.cs doesn't rebuild nearly as often as it should and you need to wipe it out before it rebuilds again.

    this helped me, thanks

    Monday, June 4, 2018 12:16 PM
  • User217716 posted

    This has plagued me off and on. Project would build but would not deploy. I would the "resouce. does not contain.....etc". What was the culprit for me was excess white space in the axml file. I would have elements where I put the "/>" on another line for ease. Well... it don like that. No white space in the after the last attribute and all of my problems went away. Another Xamarin ooops!1

    Monday, March 18, 2019 12:35 AM
  • User386274 posted

    Solved this error by saving .axml, cleaning project and finally building project

    Monday, June 3, 2019 8:16 AM
  • User147991 posted

    @Dakkon said: In my case, I was receiving resource related errors, but my solution itself would still compile. It's still annoying though to have the error list littered with false errors. It seems something in the .vs folder within my solution must have become corrupt. None of the other recommendations I tried were successful, but once I deleted the .vs folder, cleaned my solution and then re-opened studio, I no longer received the false errors. I would recommend trying this for anyone who has a similar situation.

    This did it for me. Thanks!

    Thursday, August 1, 2019 4:17 PM
  • User364448 posted

    I'm glad I was able to help.

    @RobertMolloy said:

    @Dakkon said: In my case, I was receiving resource related errors, but my solution itself would still compile. It's still annoying though to have the error list littered with false errors. It seems something in the .vs folder within my solution must have become corrupt. None of the other recommendations I tried were successful, but once I deleted the .vs folder, cleaned my solution and then re-opened studio, I no longer received the false errors. I would recommend trying this for anyone who has a similar situation.

    This did it for me. Thanks!

    Friday, August 2, 2019 12:17 PM
  • User388795 posted

    I changed the [Properties/Build Action] for each file generating that error to [Android Resource] instead of [Compile] and that worked for me

    Saturday, August 31, 2019 12:57 PM
  • User325794 posted

    Hi devs, I personally fixed this issue deleting the obj folder in the project directory.

    Wednesday, September 4, 2019 9:23 AM