2017-01-26 93 views
0

当我打开特定页面时,Xamarin.Forms应用程序不断崩溃。该崩溃是可重现的,但仅限于发布模式。当我以调试模式构建并运行应用程序时,同一页面可以正常打开。Xamarin.Forms应用程序在InitializeComponent中与FileNotFoundException崩溃

通过一些努力,我设法捕捉异常并在应用程序关闭之前在消息窗口中显示堆栈跟踪。核心错误似乎是为System.Runtime在运行XamlLoaderXamlParser装配某处FileNotFoundException当我的页面调用InitializeComponent方法:

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() 

回答

2

我的代码有很多System.Runtime有关的进口,但堆栈跟踪表明XAML中存在的问题使我能够找到真正的问题。

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

ReSharper的自动完成这给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> 

虽然这个工程在调试模式下由于某种原因,该声明引起的应用程序,你当与提到的错误崩溃释放模式创建页面。

<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=mscorlib"> 
    <!-- ... --> 
    <mc:MyControl x:TypeArguments="system:String" /> 
    <!-- ... --> 
</mp:MyPage> 
:当我改变了组件 mscorlib,应用程序在调试 发布模式工作
相关问题