2017-11-24 16 views
0

Xamarin.Android + ReactiveUIでWireUpControls()を呼び出すときに次の例外が発生します。Xamarin.Android System.TypeInitializationException: 'ReactiveUI.ControlFetcherMixin'の型初期化器が例外をスローしました

System.TypeInitializationException: のタイプ初期化子が「ReactiveUI.ControlFetcherMixin」例外

を投げた私は、次のことをチェックしましたが、私はまだ例外を取得しています。解決戦略を変更することによりhttps://reactiveui.net/docs/handbook/data-binding/xamarin-android/wire-up-controls

  • で定義されるように制御するための命名規則

    レイアウトにはListViewしかありません。

    主な活動:

    protected override void OnCreate(Bundle savedInstanceState) 
         { 
          base.OnCreate(savedInstanceState); 
    
          SetContentView(Resource.Layout.Main); 
          this.WireUpControls(ControlFetcherMixin.ResolveStrategy.ExplicitOptIn); 
          SetupUserInterface(); 
    
          this.OneWayBind(ViewModel, x => x.OutletListing, x => x.OutletListItems).DisposeWith(SubscriptionDisposables); 
    
         } 
    

    更新:あなたの実際の例外のInnerExceptionにおそらくある内部例外を発見

    +  ex {System.TypeInitializationException: The type initializer for 'ReactiveUI.ControlFetcherMixin' threw an exception. ---> System.InvalidOperationException: You're using multiple resource ID's with the same name but with different casings which isn't allowed for WireUpControls: { Image = image }, { Text = text }, { Text2 = text2 } ---> System.ArgumentException: An item with the same key has already been added. Key: image 
        at System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x000bb] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
        at System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 
        at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector, System.Func`2[T,TResult] elementSelector, System.Collections.Generic.IEqualityComparer`1[T] comparer) [0x0009e] in <b5bd9d990a0b4733885e90ca5ec6c0fb>:0 
        at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector, System.Func`2[T,TResult] elementSelector) [0x00000] in <b5bd9d990a0b4733885e90ca5ec6c0fb>:0 
        at ReactiveUI.ControlFetcherMixin..cctor() [0x00048] in C:\projects\reactiveui\src\ReactiveUI\Android\ControlFetcherMixin.cs:34 
        --- End of inner exception stack trace --- 
        at ReactiveUI.ControlFetcherMixin..cctor() [0x0010c] in C:\projects\reactiveui\src\ReactiveUI\Android\ControlFetcherMixin.cs:45 
        --- End of inner exception stack trace --- 
    
  • +0

    Forms PCLに共有クラスを設定し、Xamarin.Androidターゲットプロジェクトを変更することで、Xamarin.FormsプロジェクトをXamarin.Androidに変換しました。しかし、私はまだXamarin.AndroidプロジェクトでXamarin.Formsの参考文献を持っています。それは効果がありますか? –

    答えて

    1

    、ドキュメントでこの通路に特別な注意を取ります:

    ディクショナリは名前の小文字バリアントで索引付けされているため、異なるケーシングを持つレイアウトで同じリソース名を2回使用することはできません。 AndroidではリソースIDを生成する際に大文字と小文字が区別されるため、WireUpControlsで使用するためにこれを単一のリソースIDにマッピングすることは不可能です。

    おそらく、類似していてもケーシングが異なる複数のリソース名を使用している可能性があります。

    関連する問題