Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous reference between 'Xamarin.Forms.Label' and 'System.Reflection.Emit.Label'

I'm starting my first Xamarin.Forms app in Visual Studio 2015 on Windows.

My StartUp project is firstApp.Droid.

In MainActivity.cs in firstApp.Droid I have this code:

namespace firstApp.Droid
{
    [Activity (Label = "firstApp", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
    {
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            global::Xamarin.Forms.Forms.Init (this, bundle);
            LoadApplication (new firstApp.App ());
        }
    }
}

In App.cs I have this code:

public App ()
    {
        // The root page of your application
        MainPage = new NavigationPage(new SensorPage());
    }

And in SensorPage.cs I have this auto-generated code:

public class SensorPage : ContentPage
{
    public SensorPage ()
    {
        Content = new StackLayout {
            Children = {
                new Label { Text = "Hello SensorPage" } //line that causes the error
            }
        };
    }
}

When I try to compile the app, I get the error:

CS0104 'Label' is an ambiguous reference between 'Xamarin.Forms.Label' and 'System.Reflection.Emit.Label'

What should I do to resolve this?

like image 949
moffeltje Avatar asked Dec 02 '25 15:12

moffeltje


1 Answers

either remove using System.Reflection.Emit; from the top of your SensorPage.cs, or alternately use an explicit namespace for Label:

Content = new StackLayout {
            Children = {
                new Xamarin.Forms.Label { Text = "Hello SensorPage" }
            }
        };
like image 65
Jason Avatar answered Dec 04 '25 07:12

Jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!