<interfaces> An error has already been registered in mixing using MVVMLightV4

I used MVVMLight for some time and started using V4 since it was first available.

However, one problem always persisted with me, which I could not solve.

If I create a project using the MVVM 4 project template, the solution builds fine, works fine and works fine in blend.

However

If I run my own project and install MVVMLight V4 using Nuget, as soon as I add even a basic DataService and include the commented code in the ViewModelLocator template and open the project in Blend, I just get the error message:

"Class is already registered"

Just trying to figure out this very annoying mistake.

Just to be clear, it does not matter what the DataService has, since even with an interface and a service with only 1 empty function, it gives the same error

+6
source share
1 answer

Blend for some reason may initialize ViewModelLocator more than once.

So you need to add a check:

 if (!SimpleIoc.Default.IsRegistered<ISomeService>()) SimpleIoc.Default.Register<ISomeService, SomeService>(); 
+22
source

Source: https://habr.com/ru/post/919328/


All Articles