<Interface> is already registered error in blend using MVVMLightV4

亡梦爱人 提交于 2019-12-23 09:31:38

问题


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


回答1:


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>();


来源:https://stackoverflow.com/questions/11262878/interface-is-already-registered-error-in-blend-using-mvvmlightv4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!