MvvmLight 5.4.1 报错:“命名空间‘Practice’不存在”解决方法

MvvmLight 5.4.1 报错:“命名空间‘Practice’不存在”解决方法

  • 问题的发现
  • 解决方法

问题的发现

今天看了一个关于MvvmLight的文章,逐自建一个Demo尝试,在Nuget安装MvvmLight以后发现ViewModelLocator里面直接报错了,“using Microsoft.Practices.ServiceLocation;”提示命名空间找不到。

之前在用MvvmLight时并没有遇到过这个现象,据此怀疑是版本的问题。开始试过类型强转(这方法IDE不再报错,但是感觉后面可能还有坑没在深究),后来在原来的Demo中查找引用的dll文件,复制过来重新引用仍不能解决问题。几次折腾终于放弃挣扎投奔度娘(谁有方法请赐教)。

解决方法

各种无用的帖子和跳坑的过程不多叙述,直接列出几个有用的结果:

  1. 第一个和我想法接近,认为是版本问题的CSDN兄弟:https://blog.csdn.net/u010469446/article/details/81783210
  2. 上一个帖子给的连接找到MSDN上一个同遭遇的guy():https://social.msdn.microsoft.com/Forums/vstudio/en-US/fd795426-fa18-4484-9624-4dc4ac9142fc/how-do-i-resolve-an-error-that-says-the-namespace-practices-does-not-exist-in-the-namespace?forum=wpf
  3. 终极解决方法其实官方给出了说明:
    MVVM Light Change log

in MVVM Light Toolkit / installing

In V5.4.1

Note that I skipped V5.4.0 and went straight to V5.4.1 because I published a preview version (V5.4.0.1-alpha) and wanted to avoid confusion.

.NET Standard availability


    With this version, MVVM Light is available for .NET Standard 1.0. More details can be found here.


Common Service Locator


    Upgraded to CommonServiceLocator 2.0.2 (where possible).


MVVM Light V5.4.1 introduces support for the new CommonServiceLocator V2.0.2. Unfortunately the CommonServiceLocator developers decided to use a new namespace for this version. If you are upgrading your assemblies from MVVM Light previous to V5.4.1, you need to change the following:

1 // OLDusing
2 Microsoft.Practices.ServiceLocation;
3
4 // NEWusing
5 CommonServiceLocator;
http

http://www.mvvmlight.net/installing/changes

你可能感兴趣的:(.Net,Mvvm,MvvmLight)