无法使 IOC 在 Xamarin Forms 中工作
Unable to make IOC work in Xamarin Forms
我试图让我们的应用程序符合 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] in D:\GalaSoft\mydotnet\MVVMLight\source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\Ioc\SimpleIoc.cs:537
在 GalaSoft.MvvmLight.Ioc.SimpleIoc.GetService (System.Type serviceType) [0x00000] 在 D:\GalaSoft\mydotnet\MVVMLight\source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\Ioc\SimpleIoc。 CS: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[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /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[] parameters, System.Globalization.CultureInfo culture) [0x00050] in /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[] parameters) [0x00000] in /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/referencesource/mscorlib/system/reflection/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
at GalaSoft.MvvmLight.Ioc.SimpleIoc.DoGetService (System.Type serviceType, System.String key, System.Boolean cache) [0x000c9] in 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
在 CustomerApp.App..ctor () [0x00016] 在 C:\Xamarin Backup\CustomerApp\CustomerApp\CustomerApp\App.xaml.cs:29
我将配置文件更改为 259 并添加了 Microsoft http 客户端 nuget。这似乎可以解决问题
我试图让我们的应用程序符合 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] in D:\GalaSoft\mydotnet\MVVMLight\source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\Ioc\SimpleIoc.cs:537 在 GalaSoft.MvvmLight.Ioc.SimpleIoc.GetService (System.Type serviceType) [0x00000] 在 D:\GalaSoft\mydotnet\MVVMLight\source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras (PCL)\Ioc\SimpleIoc。 CS: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[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /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[] parameters, System.Globalization.CultureInfo culture) [0x00050] in /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[] parameters) [0x00000] in /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/referencesource/mscorlib/system/reflection/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 at GalaSoft.MvvmLight.Ioc.SimpleIoc.DoGetService (System.Type serviceType, System.String key, System.Boolean cache) [0x000c9] in 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 在 CustomerApp.App..ctor () [0x00016] 在 C:\Xamarin Backup\CustomerApp\CustomerApp\CustomerApp\App.xaml.cs:29
我将配置文件更改为 259 并添加了 Microsoft http 客户端 nuget。这似乎可以解决问题