【问题标题】:Xamarin.Android System.TypeInitializationException: The type initializer for 'ReactiveUI.ControlFetcherMixin' threw an exceptionXamarin.Android System.TypeInitializationException:“ReactiveUI.ControlFetcherMixin”的类型初始化程序引发异常
【发布时间】:2017-11-24 18:50:27
【问题描述】:

尝试使用 Xamarin.Android + ReactiveUI 调用 WireUpControls() 时出现以下异常。

System.TypeInitializationException:类型初始化器 'ReactiveUI.ControlFetcherMixin' 抛出异常

我已经检查了以下内容,但仍然遇到异常。

  1. https://reactiveui.net/docs/handbook/data-binding/xamarin-android/wire-up-controls 中定义的控件的命名约定
  2. 通过更改解决策略。

我的布局中只有一个 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);

        }

更新: 发现内部异常

+       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 ---

【问题讨论】:

  • 我通过使 Forms PCL 具有一些共享类并修改 Xamarin.Android 目标项目,将 Xamarin.Forms 项目转换为 Xamarin.Android。但我在 Xamarin.Android 项目中仍然有 Xamarin.Forms 引用。会有影响吗?

标签: xamarin.android reactiveui


【解决方案1】:

您的实际异常可能在 InnerException 中,请特别注意文档中的这段话:

因为字典是根据名称的小写变体索引的,所以您不能在具有不同大小写的布局中两次使用相同的资源名称。 Android 在生成资源 ID 时区分大小写,因此无法将其映射到单个资源 ID 以与 WireUpControls 一起使用。

您可能正在使用多个资源名称,它们相似但只是大小写不同。

【讨论】:

    猜你喜欢
    • 2018-09-01
    • 2017-08-17
    • 1970-01-01
    • 2016-11-30
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多