c# - 在新的 Xamarin.Forms 项目中抛出“System.Exception”

标签 c# xaml exception xamarin.forms

我最近在 Windows 10 Pro Fall Creators Update 上安装了 Visual Studio 2017 Community Edition 的全新副本,但我无法在 Xamarin.Forms 上正确创建新的 ContentPage (参见屏幕截图 1-3)。在我第一次尝试在新的 Xamarin.Forms 项目中创建新的 ContentPage 时,我遇到了屏幕截图 1 和 2 中显示的错误。

接下来,生成一个自动错误日志(如附件)。如果我不创建任何新项目并按原样运行,我可以在我的 Android 模拟器上成功启动该应用程序,没有任何问题。

Exception of type 'System.Exception' was thrown

Screenshot 1 - Exception of type 'System.Exception' was thrown

The project system has encountered an error.

Did not find new element in the hierarchy for item "Page2.xaml". The
item would have been added with type "Page". The project item
schema service knows about this item type. The item does exist
in the project file.

A diagnostic log has been written to the following location: "C:\..." (see below link)

Automatically generated error log file - txt

Screenshot 2 - Project system encountered an error; did not find new element in the hierarchy for item "Page2.xaml"...

当我创建一个新的 ContentPage 时出现问题。代码隐藏 .cs 文件和 .xaml 文件不会立即显示在解决方案资源管理器中。我需要手动点击 Show All Files 按钮来显示新创建的文件(如屏幕截图 3 所示)。但是,尽管多次尝试,我还是无法将它们包含到项目中。

Screenshot 3 - Newly created xaml and cs files (Page1, Page2) not immediately visible and cannot be included into project

当我打开一个 .xaml 文件(在本例中为 Page2.xaml)时,可以看到提到缺少引用和程序集的错误(请参见下面的屏幕截图 4)。

Screenshot 4 - in editor while editing xaml files - The type 'ContentPage' was not found...

到目前为止,我已经完成了以下工作:

  • 移除了 Visual Studio 中的移动应用程序开发 (Xamarin) 安装程序
  • 通过包含(检查)移动应用重新安装 Xamarin Visual Studio 安装程序中的开发 (Xamarin)

这个问题有什么已知的解决方案吗?任何帮助都将不胜感激。谢谢!

更新(2 月 27 日): 尝试了 Paul-Jan 的建议,但问题仍然存在。但是,新创建的 Page1.xaml 已正确包含并被 Solution Explorer 识别(如下所示)。 Newly created ContentPage is properly recognized

最佳答案

我在全新的 VS2017 Professional 安装中遇到过这种情况,其中在安装过程中未添加通用 Windows 平台 (UWP) 支持。当然,您可能根本不想为 UWP 进行开发,但显然,如果您不安装 Xamarin Forms 工具链,它就会丢失一些零碎的东西。

再次运行 Visual Studio 安装程序,添加 UWP 支持,会有帮助。

UWP Support checkbox in VS2017

关于c# - 在新的 Xamarin.Forms 项目中抛出“System.Exception”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48146951/

相关文章:

wpf - 登录失败时如何在没有数据绑定(bind)的情况下清除PasswordBox的内容?

XAML:将椭圆与均匀拉伸(stretch)对齐到中心

c# - 在 C# Windows 中设置 DataSource 属性时无法修改项集合

c# - 如果在 LINQ 中找到,如何在最后一条记录上应用包含并删除?

c# - 如何在 XAML 代码中创建支持其中其他元素的 UserControl

c# - 如何从异常(随机出现的 C# WPF)中获取更多信息?

python - 捕获 Neo4j 异常

c# - 如何在给定 UTC 时间和日期的情况下创建 DateTime 对象?

c# - 低功耗蓝牙扫描仪 Xamarin Android

c# - 事件处理程序中抛出的 WPF 异常被吞噬了吗?