在我尝试使用 ObservableCollection<T>
后,在针对 .NET 4.6 的 VS 2017 中创建了一个新的 WPF 项目之后在我的代码中,出现以下错误,导致应用无法构建:
ObservableCollection exists in both 'System.Windows' and 'System'
在我使用 VS 2015 创建的项目中,我引用了这两个程序集,应用程序运行良好。我尝试删除应用程序的 bin 和 obj 文件夹的内容,重新启动 VS 并执行 Build > Clean Solution 但这没有帮助。
删除对 System.Windows 的引用允许构建应用程序,但这会对其他代码产生不利影响(例如,我的 DelegateCommand 的 RaiseCanExecuteChanged 需要对 System.Windows 的引用)。
知道为什么会发生这种情况以及如何解决它吗?
更新这是完整的错误信息:
Severity Code Description Project File Line Suppression State Error CS0433 The type 'ObservableCollection' exists in both 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' and 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
最佳答案
问题是 ReSharper 正在添加对以下内容的引用:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile158\System.Windows.dll
代替:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.2\System.Windows.dll
一旦我删除了 ReSharper 添加的引用并手动添加了正确的引用,问题就解决了。
ReSharper 检测到我的 MVVM 框架使用的 ICommand 的 DelegateCommand 实现需要对 System.Windows 的引用,但错误地添加了对 NETPortable 中找到的 System.Windows 的引用,而不是 .NET 中找到的 System.Windows...
关于c# - ObservableCollection<T> 存在于 'System.Windows' 和 'System',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42891853/