【问题标题】:Xamarin UWP app does not workXamarin UWP 应用程序不起作用
【发布时间】:2017-02-05 07:26:40
【问题描述】:

我正在使用 Visual Studio Update 3 + Update 3 补丁。我使用 C# Cross-Platform 模板创建了一个空白 XAML App(Xamarin.Forms Portable) 解决方案。我在配置管理器中选中了构建和部署。我已将解决方案更新为 Xamarin.Forms 2.3.2.127(2.2 版本有同样的问题)。到目前为止,我已经能够运行 Android 和 iOS 应用程序。我没有对源代码进行任何更改,我使用的是空项目。尝试运行 UWP 应用时,App.xaml.cs 中出现错误:

Xamarin.Forms.Forms.Init(e)


System.AggregateException: One or more errors occurred. 
   (Error HRESULT E_FAIL has been returned from a call to a COM component.) ---> 
System.Runtime.InteropServices.COMException: 
   Error HRESULT E_FAIL has been returned from a call to a COM component.
--- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at Xamarin.Forms.Platform.UWP.WindowsBasePlatformServices.GetAssemblies()
   at Xamarin.Forms.Registrar.RegisterAll(Type[] attrTypes)
   at Xamarin.Forms.Forms.Init(IActivatedEventArgs launchActivatedEventArgs, IEnumerable`1 rendererAssemblies)
   at Tester.UWP.App.OnLaunched(LaunchActivatedEventArgs e)
---> (Inner Exception #0) System.Runtime.InteropServices.COMException (0x80004005): 
       Error HRESULT E_FAIL has been returned from a call to a COM component.

【问题讨论】:

    标签: c# xamarin.forms


    【解决方案1】:

    您可以尝试清理 UWP 项目并重新构建。

    【讨论】:

    • 我正在使用使用 C# 跨平台的空白 XAML 应用程序(Xamarin.Forms Portable)解决方案,没有添加任何代码。 UWP 项目在 Xamarin.Forms.Forms.Init(e) 失败
    • 你运行什么目标? Windows 10 桌面版 Windows 10 模拟器 Windows 10 移动版模拟器 Windows 10 手机版
    • Windows 10 桌面版
    • 你能上传你的示例项目,让我在我的电脑上试试吗?
    • 那行得通。问题似乎出在 UWP 尝试初始化 Xamarin 时:Xamarin.Forms.Forms.Init(e)
    【解决方案2】:

    在 Windows 10 Enterprise 2015 LTSB 上运行 Visual Studio 2015 作为 VMware Fusion 版本 8.5.0 (4352717) 中的来宾操作系统时,我遇到了完全相同的问题。主机操作系统是 OSX El Captitan 10.11.6。

    否则我有相同的设置:空白 Xamarin 项目(共享和便携式)在运行 UWP 项目时具有完全相同的结果。 Xamarin 网站上的 TodoREST 示例也是如此。

    使用 VS 调试时,有几个 System.InvalidCastException 出现在 Xamarin.Forms.Forms.Init(e) 断点处的“this”、“e”和“rootFrame”中;即:

        this.FocusVisualKind' threw an exception of type 'System.InvalidCastException
        at System.StubHelpers.StubHelpers.GetCOMIPFromRCW_WinRT(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget)\r\n   at Windows.UI.Xaml.Application.get_FocusVisualKind()"
        Message "Unable to cast object of type 'TodoREST.UWP.App' to type 'Windows.UI.Xaml.IApplication2'."
    

    我尝试了几件事

    • 尽可能更新
    • 清理任何可能的东西
    • 逐步将 Xamarin 降级到 2.0
    • 从 Xamarin 下载站点(包括 Xamarin 4.1)重新安装 VS2015 社区
    • 之后重新安装 VS2015 Community plain 和 Xamarin 4.2

    但似乎对此异常没有任何影响。

    最后我选择了一台物理的 Windows 10 笔记本电脑,它的工作原理就像一个魅力。

    所以我最好的猜测是,Windows 在 VMware 中作为访客操作系统运行这一事实与此错误有关。

    由于我已经在这方面浪费了太多时间,所以我唯一要做的就是将 OSX 更新到 Sierra。要么它有效,要么我将继续使用“本机”Windows 解决方法。

    【讨论】:

    • 更新到 Sierra 并没有改变任何事情。
    猜你喜欢
    • 2020-06-14
    • 2018-10-23
    • 1970-01-01
    • 2021-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-29
    相关资源
    最近更新 更多