【问题标题】:Unable to make IOC work in Xamarin Forms无法使 IOC 在 Xamarin Forms 中工作
【发布时间】:2017-02-04 10:41:35
【问题描述】:

我试图让我们的应用程序符合 mvvm。目前所有的代码都写在代码后面。我决定使用 SimpleIOC 和 MVVM Light。但出于某种原因就是不想工作。我在配置文件 111 上运行。我已经注册了我的类和接口。当我尝试解决它们时,这是我得到这个异常的异常。有什么指点吗?

System.Reflection.TargetInvocationException:调用的目标已抛出异常。 ---> Microsoft.Practices.ServiceLocation.ActivationException:在缓存中找不到类型:CustomerApp.Service.RestClient.IApiClient。 在 GalaSoft.MvvmLight.Ioc.SimpleIoc.DoGetService (System.Type serviceType, System.String key, System.Boolean cache) [0x0003f] 在 D:\GalaSoft\mydotnet\MVVMLight\source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\Ioc\SimpleIoc.cs:537 在 D:\GalaSoft\mydotnet\MVVMLight\source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\Ioc\SimpleIoc.cs 中的 GalaSoft.MvvmLight.Ioc.SimpleIoc.GetService (System.Type serviceType) [0x00000]: 789 在 GalaSoft.MvvmLight.Ioc.SimpleIoc.MakeInstance[TClass] () [0x00064] 在 D:\GalaSoft\mydotnet\MVVMLight\source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\Ioc\SimpleIoc.cs:729 在(包装器托管到本机) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) 在 System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] 参数, System.Globalization.CultureInfo 文化) [0x00038] 在 /Users/builder /data/lanes/3819/c1d1c79c/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:305 --- 内部异常堆栈跟踪结束 --- 在 System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] 参数, System.Globalization.CultureInfo 文化) [0x00050] 在 /Users/builder /data/lanes/3819/c1d1c79c/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:313 在 System.Reflection.MethodBase.Invoke(System.Object obj,System.Object[] 参数)[0x00000] 在 /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/referencesource/mscorlib/系统/反射/methodbase.cs:229 在 System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00107] 在 /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/corlib/System/Delegate.cs:461 在 System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x0000b] 在 /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/corlib/System/MulticastDelegate.cs:67 在 System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] 在 /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/corlib/System/Delegate.cs:406 在 GalaSoft.MvvmLight.Ioc.SimpleIoc.DoGetService (System.Type serviceType, System.String key, System.Boolean cache) [0x000c9] 在 D:\GalaSoft\mydotnet\MVVMLight\source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\Ioc\SimpleIoc.cs:567 在 GalaSoft.MvvmLight.Ioc.SimpleIoc.GetInstance[TService] () [0x00000] 在 D:\GalaSoft\mydotnet\MVVMLight\source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\Ioc\SimpleIoc.cs:912 在 C:\Xamarin Backup\CustomerApp\CustomerApp\CustomerApp\App.xaml.cs:29 中的 CustomerApp.App..ctor () [0x00016]

【问题讨论】:

  • 发布代码的相关部分总是一个好主意。单独的堆栈跟踪并没有那么有用
  • 你在哪里注册你的 IoC 容器?
  • 我猜 SimpleIOC.... 没那么简单。

标签: mvvm xamarin dependency-injection xamarin.forms inversion-of-control


【解决方案1】:

我将个人资料更改为 259 并添加了 Microsoft http 客户端 nuget。这似乎可以解决问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 2021-03-02
    • 2022-01-15
    • 1970-01-01
    相关资源
    最近更新 更多