c# - Xamarin - 找不到类型或命名空间名称 'App'

标签 c# ios xamarin xamarin.forms xamarin.ios

目前在尝试将我的 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);
        }
    }
}

最佳答案

我在 Android 和 iOS 上遇到了类似的问题,但我的可以正常构建和运行,只是两个项目的 App 下都有红色下划线。

我通过右键单击 Android References->Add Reference->Projects 然后取消选中已包含的共享项目单击 OK 来修复它。 然后我重新添加了共享项目并修复了错误。

请注意,在最新的 Visual Studio 版本(现在是 .Net Standard)中启动 Xamarin.Forms 项目时,不再需要 PCL。

关于c# - Xamarin - 找不到类型或命名空间名称 'App',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47872531/

相关文章:

c# - 在 HierarchicalDataTemplate 中过滤

ios - 归档应用程序在管理器屏幕上生成模糊的图标

c# - 获取响应流时出错 (ReadDone2) : Receive Failure

android - Xamarin Native Facebook 与 Xamarin.Forms 混合

azure - 如何使 API 始终可访问,而不仅仅是在项目执行时访问?

c# - 反序列化 JSON 凭证数据时出错 C# Google Sheets API

c# - 如何在.Net中播放定义了开始时间和结束时间的声音

c# - 使用 C# 将内联 XML 节点转换为 asp.net 中的嵌套节点

ios - 准备segue不发送所有信息(Swift)

ios - 从几张图片中剖析ImageView