在 System.Collections.ObjectModel 中找不到 ObservableCollection
两个 WPF 项目,同一台机器,浏览 Collections.ObjectModel
一个有 ObservableCollections 并说
// Type: System.Collections.ObjectModel.ObservableCollection`1
// Assembly: System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.dll
另一个(从 3.0 项目升级)没有,并说
// Type: System.Collections.ObjectModel.Collection`1
// Assembly: mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll
为什么第二个使用 System.Collections.ObjectModel 的引用如此不同?
Two WPF projects, same machine, browse Collections.ObjectModel
one has ObservableCollections and says
// Type: System.Collections.ObjectModel.ObservableCollection`1
// Assembly: System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.dll
The other (was upgraded from a 3.0 project,) does not and says
// Type: System.Collections.ObjectModel.Collection`1
// Assembly: mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll
Why is the second reference to using System.Collections.ObjectModel so different?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在寻找两种不同的类型。不同程序集中的类型可以位于同一命名空间中。
由于升级后的项目不包含对 System.dll 程序集的引用(在 3.0 中它位于 Windowsbase.dll 中),因此它不会具有 ObservableCollection。如果添加对该程序集的引用,您将可以访问该集合。
You are looking at 2 different types. Types in different assemblies can be in the same namespace.
Since your upgraded project doesn't include a reference to the System.dll assembly (in 3.0 it was in Windowsbase.dll), it won't have the ObservableCollection. If you add a reference to that assembly, you will have access to that collection.
查看系统程序集“v4.0\Profile\Client\System.dll”与“Framework\v2.0.50727\mscorlib.dll”的末尾
该项目设置为使用客户端配置文件。进入项目属性并选择完整的 .Net 4 配置文件。
Look at the end of the System assembly "v4.0\Profile\Client\System.dll" vs "Framework\v2.0.50727\mscorlib.dll"
That project is set to use the client profile. Go into project properties and select the full .Net 4 profile instead.
我有多个项目。主项目设置为 .net 4,但引用的项目仍然是 .net 3.5,并且引用 2.0 mscorlib。
I have multiple projects. The main project was set to .net 4 but the referenced project was still .net 3.5 and it was referencing the 2.0 mscorlib.