开发者

Can't find ObservableCollection in System.Collections.ObjectModel

开发者 https://www.devze.com 2023-03-25 19:43 出处:网络
Two WPF projects, same machine, browse Collections.ObjectModel one has ObservableCollections and says // Type: System.Collections.ObjectModel.ObservableCollection`1

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?


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消