Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<Interface> is already registered error in blend using MVVMLightV4

Tags:

mvvm-light

I've been using MVVMLight for some time now and started using V4 since it was first made available.

However one issue has always persisted with me which I've been unable to solve.

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

However

If I start my own project and install MVVMLight V4 using Nuget, as soon as I add even a basic DataService and enable the commented out code in the ViewModelLocator template and open up the project in Blend I just get an error:

"Class is already registered"

Just trying to get to the bottom of this very annoying error.

Just to be clear it doesn't matter what is in the DataService as even with an interface and service with only 1 empty function gives the same error

like image 661
Darkside Avatar asked Jun 29 '12 13:06

Darkside


1 Answers

Blend, for some reason, may initialize the ViewModelLocator more than once.

So you need to add a check:

if (!SimpleIoc.Default.IsRegistered<ISomeService>())
    SimpleIoc.Default.Register<ISomeService, SomeService>();
like image 139
trydis Avatar answered May 16 '23 09:05

trydis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!