'Xamarin.Forms.Label'和'System.Reflection.Emit.Label'之间的模糊引用

mof*_*tje 3 c# android visual-studio xamarin xamarin.forms

我正在Windows上的Visual Studio 2015中开始我的第一个Xamarin.Forms应用程序.

我的StartUp项目是firstApp.Droid.

firstApp.Droid的MainActivity.cs中,我有以下代码:

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 ());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

App.cs中我有这个代码:

public App ()
    {
        // The root page of your application
        MainPage = new NavigationPage(new SensorPage());
    }
Run Code Online (Sandbox Code Playgroud)

SensorPage.cs中,我有这个自动生成的代码:

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

当我尝试编译应用程序时,我收到错误:

CS0104'Label'是'Xamarin.Forms.Label'和'System.Reflection.Emit.Label'之间的模糊引用.

我该怎么做才能解决这个问题?

Jas*_*son 6

要么using System.Reflection.Emit;从SensorPage.cs的顶部删除,要么使用Label的显式命名空间:

Content = new StackLayout {
            Children = {
                new Xamarin.Forms.Label { Text = "Hello SensorPage" }
            }
        };
Run Code Online (Sandbox Code Playgroud)