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

时间:2015-10-27 12:15:44

标签: 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 ());
        }
    }
}

App.cs 中,我有以下代码:

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

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

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

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

  

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

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

1 个答案:

答案 0 :(得分:6)

从SensorPage.cs顶部删除using System.Reflection.Emit;,或者替换地使用Label的显式命名空间:

Content = new StackLayout {
            Children = {
                new Xamarin.Forms.Label { Text = "Hello SensorPage" }
            }
        };