簡體   English   中英

的ObservableCollection <T> 存在於&#39;System.Windows&#39;和&#39;System&#39;中

[英]ObservableCollection<T> exists in both 'System.Windows' and 'System'

在我嘗試在我的代碼中使用ObservableCollection<T> ,在VS 2017中針對.NET 4.6創建新的WPF項目后,我收到以下錯誤,導致應用無法構建:

ObservableCollection存在於'System.Windows'和'System'中

在我在VS 2015中創建的項目中,我引用了這兩個程序集,應用程序工作得很好。 我嘗試刪除app的bin和obj文件夾的內容,重新啟動VS並執行Build> Clean Solution但這沒有幫助。

刪除對System.Windows的引用允許構建應用程序,但這會對其他代碼產生負面影響(例如,我的DelegateCommand的RaiseCanExecuteChanged需要對System.Windows的引用)。

知道為什么會這樣,以及如何解決它?

更新以下是完整的錯誤消息:

嚴重級代碼描述項目文件行抑制狀態錯誤CS0433類型'ObservableCollection'存在於'System.Windows,Version = 2.0.5.0,Culture = neutral,PublicKeyToken = 7cec85d7bea7798e,Retargetable = Yes'和'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 ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM