c# – Xamarin – 无法找到类型或命名空间名称“App”

前端之家收集整理的这篇文章主要介绍了c# – Xamarin – 无法找到类型或命名空间名称“App”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
目前正在尝试将我的Xamarin应用程序运行到我的iPhone实时播放器时出现此错误.
  1. "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:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using COCApp;
  6.  
  7. using Xamarin.Forms;
  8.  
  9. namespace COCApp
  10. {
  11. public partial class App : Application
  12. {
  13. public App()
  14. {
  15. InitializeComponent();
  16. MainPage = new NavigationPage(new MainPage());
  17. }
  18.  
  19. protected override void OnStart()
  20. {
  21. // Handle when your app starts
  22. }
  23.  
  24. protected override void OnSleep()
  25. {
  26. // Handle when your app sleeps
  27. }
  28.  
  29. protected override void OnResume()
  30. {
  31. // Handle when your app resumes
  32. }
  33. }
  34. }

AppDelegate.cs

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using COCApp;
  5. using Foundation;
  6. using UIKit;
  7.  
  8. namespace COCApp.iOS
  9. {
  10. // The UIApplicationDelegate for the application. This class is responsible for launching the
  11. // User Interface of the application,as well as listening (and optionally responding) to
  12. // application events from iOS.
  13. [Register("AppDelegate")]
  14. public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
  15. {
  16. //
  17. // This method is invoked when the application has loaded and is ready to run. In this
  18. // method you should instantiate the window,load the UI into it and then make the window
  19. // visible.
  20. //
  21. // You have 17 seconds to return from this method,or iOS will terminate your application.
  22. //
  23. public override bool FinishedLaunching(UIApplication app,NSDictionary options)
  24. {
  25. global::Xamarin.Forms.Forms.Init();
  26. LoadApplication(new App());
  27.  
  28. return base.FinishedLaunching(app,options);
  29. }
  30. }
  31. }

解决方法

我在Android和iOS上遇到了类似的问题,但是我的构建和运行都很好,除了两个项目下的App下都有红色下划线.

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

请注意,在最新的Visual Studio版本中启动Xamarin.Forms项目时,PCL已不再是它的.Net标准.

猜你在找的C#相关文章