Xamarin - 找不到“App”的类型或命名空间

9

我尝试将我的Xamarin应用程序运行到我的iPhone实时播放器时,出现了如下错误:

"AppDelegate.cs(1,1): error: The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?)"

我的解决方案构建没有错误,所以有点困惑。这些错误在我更新到最新版本之后才出现。非常感谢任何帮助。

App.xaml.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COCApp;

using Xamarin.Forms;

namespace COCApp
{
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
            MainPage = new NavigationPage(new MainPage());
        }

        protected override void OnStart()
        {
            // Handle when your app starts
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
}

AppDelegate.cs

using System;
using System.Collections.Generic;
using System.Linq;
using COCApp;
using Foundation;
using UIKit;

namespace COCApp.iOS
{
    // The UIApplicationDelegate for the application. This class is responsible for launching the 
    // User Interface of the application, as well as listening (and optionally responding) to 
    // application events from iOS.
    [Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        //
        // This method is invoked when the application has loaded and is ready to run. In this 
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }
    }
}

你尝试过使用模拟器/仿真器或真实设备运行应用程序吗? - EvZ
我已经尝试过两种方法,我的 Android 模拟器无法始终部署,在真实设备上运行 Xamarin player iOS 应用程序。 - Jacob Dillson
你尝试过从IOS解决方案中删除bin和Obj文件,然后关闭VS,再重新构建吗?这对我大多数情况下都有效。 - bhavya joshi
3个回答

12

我遇到了一个类似的问题,对于Android和iOS都是这样,但我的应用程序可以构建和运行,只是在两个项目中的App下有一个红色下划线。

我通过右键单击Android References->Add Reference->Projects然后取消选中已经包括的共享项目,点击OK来解决它。 然后我重新添加了共享项目,这样就修复了错误。

请注意,在最新版本的Visual Studio中启动Xamarin.Forms项目时,PCL不再是一个事情,现在是 .Net Standard。


3
检查你的项目,确保它引用了PCL。请参考以下截图:enter image description here

我已经添加了,虽然回答不错! - Jacob Dillson
解决方案 -> 属性 -> 配置映射:选择您所需的配置(配置:平台),并选中核心/共享项目复选框。 - ColeX
尝试过了,似乎对我的错误没有任何作用。 - Jacob Dillson

2
似乎是因为您命名项目的方式不同。我的项目名称是“Project Name”,但在引用中被导入为“Project_Name”,这并不存在,因此我只需删除该引用,然后转到Android References->Add Reference->Projects添加正确的引用。现在,当我创建新文件时,命名空间就像“Project Name”,并且存在错误,所以最终我重新创建了该项目,但这次没有在名称中使用空格。

没错,我的项目名称包含破折号,我不得不重新添加我的跨平台项目。 - Kapusch

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接