0

I just installed the latest update of Xamarin for Visual Studio. Ever since, android can't find the views in my activity layouts. Apparently the auto-generated IDs aren't updated correctly when i just save my resources.

If I clean the project and rebuild, my app runs fine. But after like 20 minutes of coding the problem will occur again.

Simple code: Resources/Layout/Main.axml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="25px"
    android:minHeight="25px"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="9dp"
        android:paddingBottom="9dp">
        <Button
            android:text="@string/action_stockcount"
            android:layout_width="match_parent"
            android:layout_height="90dp"
            android:id="@+id/btnStockCount"
            android:layout_marginLeft="18dp"
            android:layout_marginRight="18dp"
            android:layout_marginStart="9dp"
            android:layout_marginTop="9dp"
            android:textColor="@color/menu_button_text"
            android:textSize="30dp"
            android:drawableLeft="@drawable/menu_stockcount_big"
            android:paddingLeft="18dp"
            android:paddingRight="18dp"
            android:paddingBottom="9dp"
            android:paddingTop="9dp" />
    </LinearLayout>
</ScrollView>

MainActivity.designer.cs:

using ...

namespace MyApp.Droid.Activities
{
    public partial class MainActivity
    {
        private Button btnStockCount;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);
            SetTitle(Resource.String.ApplicationName);

            btnStockCount = FindViewById<Button>(Resource.Id.btnStockCount);

            // From time to time, this gives a NullReferenceException
            btnStockCount.Click += BtnStockCount_Click;

            InitComplete(savedInstanceState);
        }
    }
}

MainActivity.cs (Not quite important):

using ...

namespace MyApp.Droid.Activities
{
    public partial class MainActivity : Activity
    {
        private void BtnStockCount_Click(object sender, EventArgs e)
        {
            StartActivity(typeof(IndexStockCountActivity));
        }
    }
}

I know how android works, I know how Xamarin works. Why would the latest update of Xamarin cause this issue (the IDs that aren't updated correctly when saving a resource)? What can I do to solve this issue?

It's really annoying to have to debug my project, notice that again it's not working well, and having to clean and rebuild, and notice that after that it IS working.

I also already noticed that when it's not working, after I cleaned and rebuilded the Resource Ids are in fact changed.

Cheers

  • What actual version are you using? (as there are stable, beta, alpha release channels...) – SushiHangover Jun 07 '18 at 07:42
  • Microsoft Visual Studio 2015 Update 2 (for Windows) Xamarin 4.9.0.749 Xamarin Designer 4.10.58 Xamarin.Android SDK 8.2.0.15 Don't know if it was the beta. I suppose not since they actually pushed me toward the update. – user3582780 Jun 07 '18 at 07:49
  • I can confirm that this problem also happens to other projects, so it's definitely the update that's causing the issue – user3582780 Jun 14 '18 at 10:00

0 Answers0