2017-01-26 36 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,應用程序在調試 發佈模式工作
相關問題