2016-11-12 17 views
1

我不斷收到這個錯誤,我基本上覆制了this tutorial的所有代碼,所以我不明白爲什麼它不在這裏工作。Xamarin Forms:System.Reflection.TargetInvocationException

namespace BHASIVCBULLETIN1 { 
     using System; 
     using Xamarin.Forms; 
     using Xamarin.Forms.Xaml; 


     public partial class App : global::Xamarin.Forms.Application { 

      [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")] 
      private void InitializeComponent() { 
    -->   this.LoadFromXaml(typeof(App)); 
      } 
     } 
    } 

以上是錯誤代碼,它是在運行時生成的。

<?xml version="1.0" encoding="UTF-8"?> 
<p:ListDataPage xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
        xmlns:p="clr-namespace:Xamarin.Forms.Pages;assembly=Xamarin.Forms.Pages" 
        x:Class="BHASIVCBULLETIN1.LinkerPage" 
        Title="Sessions" StyleClass="Events"> 

<p:ListDataPage.DataSource> 
    <p:JsonDataSource Source="http://demo3143189.mockable.io/sessions" /> 
</p:ListDataPage.DataSource> 

這是鏈接的網頁代碼

using System; 
using System.Collections.Generic; 
using Xamarin.Forms.Pages; 
using Xamarin.Forms; 

namespace BHASIVCBULLETIN1 
{ 
    public partial class LinkerPage : Xamarin.Forms.Pages.ListDataPage 
    { 
     public LinkerPage() 
     { 
      InitializeComponent(); 

     } 
    } 
} 

這是我主要的應用程序的C#代碼

using Xamarin.Forms; 
using System.Collections.Generic; 
namespace BHASIVCBULLETIN1 { 
public partial class App : Application 
{ 
    public App() 
    { 
     InitializeComponent(); 

     MainPage = new NavigationPage(new LinkerPage()); 
    } 

    protected override void OnStart() 
    { 
     // Handle when your app starts 
    } 

    protected override void OnSleep() 
    { 
     // Handle when your app sleeps 
    } 

    protected override void OnResume() 
    { 
     // Handle when your app resumes 
    } 
} 

}

這是我的主要應用程序的XML代碼

<Application xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:mytheme="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Dark" 
     x:Class="BHASIVCBULLETIN1.App"> 
    <Application.Resources> 
     <!-- Application resource dictionary --> 
     <ResourceDictionary MergedWith="mytheme:DarkThemeResources" /> 
     <!-- above xml code rferences the datapages nuget packages and resources that allow the methods to be used to create the GUI--> 
    </Application.Resources> 
</Application> 

回答

0

不知道這是一個錯字錯誤,但標籤<p:ListDataPage>未關閉

1

我遇到了同樣的問題,也跟着指示明確。

看起來: <ResourceDictionary MergedWith="mytheme:DarkThemeResources"/> 以某種方式失敗,並且將App對象留下未定義的結果。 我開始認爲這是Xamarin.Forms.Themes需要解決的錯誤。我的理解是它是一個「預發佈」版本,所以也許它仍然不可靠。

更多... 我使用Xamarin新的空白跨平臺模板創建的默認引用,測試了新的空Xamarin表單項目(VS2015)的主題功能。這引用Xamarin.Forms和Xamarin.forms.pages版本2.3.0.38-pre2(在我的情況)。主題與這些參考一起工作。

將最新的Nuget更新應用到窗體和頁面(2.3.3.168)之後,主題預覽不再有效並重現您指示的同一錯誤。在我看來,Xamarin.Forms.Themes根本不符合Xamarin最新發布的程序集。

0

更新至Xamarin.Forms 2.3.3.168後,我也遇到了應用程序崩潰Xamarin.Forms.Themes 1.0.0.43-pre1。這只是在Android上,所以我不確定這個問題是否也發生在iOS或WP版本上。我從Xamarin.Forms 2.3.3.152-pre2升級,它工作得很好。

<prism:PrismApplication xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     xmlns:prism="clr-namespace:Prism.Unity;assembly=Prism.Unity.Forms" 
     xmlns:mytheme="clr-namespace:Xamarin.Forms.Themes;assembly=Xamarin.Forms.Theme.Light" 
     x:Class="myApp.App"> 
    <Application.Resources> 
     <!-- Xamarin.Forms.Themes 1.0.0.43-pre1 is broken with Xamarin.Forms 2.3.3.168 --> 
     <!--<ResourceDictionary MergedWith="mytheme:LightThemeResources">--> 
     <ResourceDictionary> 
      <!-- theme definitions --> 
     </ResourceDictionary> 
    </Application.Resources> 
</prism:PrismApplication> 

解決方案現在是,直到修復被釋放,以刪除對Xamarin.Forms.Theme的"MergedWith"參考。或者,將XF版本回滾到與主題包兼容的版本。