簡體   English   中英

Xamarin - 找不到類型或命名空間名稱“App”

[英]Xamarin - The type or namespace name 'App' could not be found

當前嘗試將我的 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?)"

我的解決方案構建沒有錯誤,所以有點卡住了。 這些錯誤直到我更新到最近的更新后才發生。 任何幫助是極大的贊賞。

應用程序.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 然后取消選中已包含的共享項目單擊確定來修復它。 然后我重新添加了共享項目並修復了錯誤。

請注意,在最新的 Visual Studio 版本(現在的 .Net Standard)中啟動 Xamarin.Forms 項目時,不再需要 PCL。

檢查您的項目以確保它引用了 PCL。

在此處輸入圖片說明

似乎是因為您如何命名項目。 我的被​​稱為“項目名稱”,但在引用中它被導入為不存在的“Project_Name”,所以我只是刪除了該引用並通過轉到 Android 引用->添加引用->項目添加了一個正確的引用。 現在,當我創建新的文件命名空間時就像“項目名稱”並且有錯誤,所以我最終重新創建了項目,但這次名稱中沒有空格

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM