[英]Xamarin Forms Previewer gets ArgumentNullException on UnityContainer.RegisterInstance
I am trying to use Xamarin Forms Previewer in my Project with MVVM Prism and Unity Container and I am getting this error: 我试图在我的项目中将Xamarin Forms Previewer与MVVM Prism和Unity Container一起使用,但出现此错误:
Here is the extracted stack for reference: 这是提取的堆栈供参考:
Xamarin.VisualStudio.ActivationManager|Error|0| Xamarin.VisualStudio.ActivationManager |错误| 0 | The renderer encountered an error while rendering this file: System.ArgumentNullException: Value cannot be null. 渲染器在渲染此文件时遇到错误:System.ArgumentNullException:值不能为null。 Parameter name: instance 参数名称:实例
at Microsoft.Practices.Unity.UnityContainer.RegisterInstance (System.Type t, System.String name, System.Object instance, Microsoft.Practices.Unity.LifetimeManager lifetime) in :0 在Microsoft.Practices.Unity.UnityContainer.RegisterInstance(System.Type t,System.String名称,System.Object实例,Microsoft.Practices.Unity.LifetimeManager生存期)中:0
at Microsoft.Practices.Unity.UnityContainerExtensions.RegisterInstance[TInterface] (Microsoft.Practices.Unity.IUnityContainer container, TInterface instance) in :0 在Microsoft.Practices.Unity.UnityContainerExtensions.RegisterInstance [TInterface](Microsoft.Practices.Unity.IUnityContainer容器,TInterface实例)中,位于:: 0
at SellerNS.Bootstrapper.RegisterTypes () in C:\\Users\\myrepo\\Bootstrapper.cs:48 在C:\\ Users \\ myrepo \\ Bootstrapper.cs:48中的SellerNS.Bootstrapper.RegisterTypes()
at Prism.Unity.UnityBootstrapper.Run () in :0 在Prism.Unity.UnityBootstrapper.Run()中:: 0
at Prism.Bootstrapper.Run (Xamarin.Forms.Application app) in :0 在Prism.Bootstrapper.Run(Xamarin.Forms.Application应用程序)中:: 0
at SellerNS.App..ctor () in C:\\Users\\myrepo\\Seller\\App.xaml.cs:20 在C:\\ Users \\ myrepo \\ Seller \\ App.xaml.cs:20中的SellerNS.App..ctor()
at at offset 12 in file:line:column :0:0 在file:line:column:0:0的偏移量12处
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) in /Users/builder/data/lanes/4009/3a62f1ea/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:661 在/Users/builder/data/lanes/4009/3a62f1ea/source/mono/mcs/class/corlib/System.Reflection/MonoMethod中的System.Reflection.MonoCMethod.InternalInvoke(System.Object obj,System.Object []参数)处的.cs:661
I am using: 我在用:
Any idea how to fix it? 知道如何解决吗?
I was getting a similar error with the Xamarin Forms Previewer when using Prism and it was resolved by adding a empty default constructor in App.xaml.cs as indicated here: https://github.com/PrismLibrary/Prism/issues/1037 使用Prism时,我在Xamarin Forms Previewer中遇到了类似的错误,并且通过在App.xaml.cs中添加一个空的默认构造函数来解决此问题,如下所示: https : //github.com/PrismLibrary/Prism/issues/1037
So adding public App() : this(null) { }
to App.xaml.cs worked for me. 因此,将public App() : this(null) { }
到App.xaml.cs对我有用。
Also, once I made the suggested change above, I had to clean the whole solution, rebuild it and then restart Visual Studio before launching the Xamarin.Forms Previewer again to get it all working as required. 另外,一旦完成上述建议的更改,就必须清理整个解决方案,重新构建它,然后重新启动Visual Studio,然后再次启动Xamarin.Forms Previewer,以使所有功能都能按要求工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.