Xamarin.Forms应用程序在InitializeComponent中与FileNotFoundException崩溃

时间:2017-01-26 22:32:03

标签: xaml xamarin.forms initializecomponent

当我打开特定页面时,我的Xamarin.Forms应用程序会一直崩溃。崩溃是可重现的,但仅限于发布模式。当我在调试模式下构建并运行应用程序时,同样的页面打开正常。

通过一些努力,我设法捕获异常并在应用程序关闭之前在消息窗口中显示堆栈跟踪。在我的网页调用FileNotFoundException方法时运行的System.Runtime的{​​{1}}中的XamlParser程序集的核心错误似乎是XamlLoader:< / p>

InitializeComponent

1 个答案:

答案 0 :(得分:2)

我的代码有很多System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime' or one of its dependencies File name: 'System.Runtime' at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity) at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef) at (wrapper remoting-invoke-with-check) System.AppDomain:Load (System.Reflection.AssemblyName) at System.Reflection.Assembly.Load (System.Reflection.AssemblyName assemblyRef) at Xamarin.Forms.Xaml.XamlParser.GetElementType (Xamarin.Forms.Xaml.XmlType xmlType, IXmlLineInfo xmlInfo, System.Reflection.Assembly currentAssembly, Xamarin.Forms.Xaml.XamlParseException& exception) at Xamarin.Forms.Xaml.CreateValuesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode node, INode parentNode) at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) at Xamarin.Forms.Xaml.RootNode.Accept (IXamlNodeVisitor visitor, INode parentNode) at Xamarin.Forms.Xaml.XamlLoader.Visit (Xamarin.Forms.Xaml.RootNode rootnode, Xamarin.Forms.Xaml.HydratationContext visitorContext) at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.String xaml) at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.Type callingType) at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml] (Xamarin.Forms.Xaml.TXaml view, System.Type callingType) at MyApp.MyNamespace.Pages.MyPage.InitializeComponent () at MyApp.MyNamespace.Pages.MyPage..ctor () 相关的导入,但是指示XAML中的问题的堆栈跟踪使我能够找到真正的问题。

问题是该页面上的通用视图,其中type参数为“system:String”。

Resharper自动完成此操作以导入System.Runtime程序集:

System.Runtime

虽然由于某种原因这在调试模式下有效,但在发布模式下,声明会导致应用程序在创建页面时因上述错误而崩溃。当我将程序集更改为 <mp:MyPage x:Class="MyApp.MyNamespace.Pages.MyPage" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:mc="clr-namespace:MyApp.MyNamespace.Controls;assembly=MyApp" xmlns:mp="clr-namespace:MyApp.MyNamespace.Pages;assembly=MyApp" xmlns:system="clr-namespace:System;assembly=System.Runtime"> <!-- ... --> <mc:MyControl x:TypeArguments="system:String" /> <!-- ... --> </mp:MyPage> 时,该应用程序在Debug Release模式下工作:

mscorlib
相关问题