none
Error: The type 'System.Windows.DependencyObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows, Version=2.0.5.0

    Question

  • Hi

    I have an ObservableCollection which I would like to sort.

    List
    <TLstNodeData> SWNodeList = TopNode.SubNodes.OrderBy(SNode => SNode.NodeDispText).ToList();

    In a WindowsForm application targeting the .NET 4.0 Framework it compiles and works as expected.

    If I do this in a WCF Service in my web project also targeting the .NET 4.0 Framework I get the following error.

    Error 1 The type 'System.Windows.DependencyObject' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.

    When I add this assembly
    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Windows.dll

    I have the next problem

    Error 22 The type 'System.Collections.ObjectModel.ObservableCollection<T>' exists in both 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll' and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\System.Windows.dll'

    Any help appreciated

    Wednesday, November 24, 2010 2:49 PM

Answers

  • Hello, is TLstNodeData a Silverlight class that is derived from DependencyObject? If so, you cannot use it in a desktop .NET application. It shouldn't work in Windows Forms either. If you have the source code of this class, please create a class library that targets desktop .NET, and reference the class library and WindowsBase.dll in your WCF project.

    You cannot share assemblies between Silverlight and desktop .NET. You can only share source code files.

    Addionally, you can't serialize a DependencyObject using DataContractSerializer. So don't try to return a DependencyObject from an operation contract, and don't try to use it a sa parameter of an operation contract.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Luzius2 Thursday, November 25, 2010 8:38 AM
    Thursday, November 25, 2010 2:35 AM

All replies

  • The second error you are seeing is occuring because a type is defined in two different assemblies and the system doesn't know which one to use. The reference to Windows.dll you added is a Silverlight assembly, are you creating a Silverlight app? If not make sure you add a reference to the Windows.dll from the regular .NET directory, for example: C:\Windows\Microsoft.NET\Framework\v4.0.30319

    Thanks,

    Michael Green
    WCF Documentation Team

    Wednesday, November 24, 2010 10:47 PM
  • Hello, is TLstNodeData a Silverlight class that is derived from DependencyObject? If so, you cannot use it in a desktop .NET application. It shouldn't work in Windows Forms either. If you have the source code of this class, please create a class library that targets desktop .NET, and reference the class library and WindowsBase.dll in your WCF project.

    You cannot share assemblies between Silverlight and desktop .NET. You can only share source code files.

    Addionally, you can't serialize a DependencyObject using DataContractSerializer. So don't try to return a DependencyObject from an operation contract, and don't try to use it a sa parameter of an operation contract.


    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Luzius2 Thursday, November 25, 2010 8:38 AM
    Thursday, November 25, 2010 2:35 AM
  • Hello Yi-Lun

    I solved the problem. The cause was a reference to a Silverlight Class Library basically to share some definitions, most of them enums, between the services and the Silverlight apps. But in the same library I had also a few commonly used functions like a helper to handle mouse doubleclicks which referenced the Silverlight System.Windows, Version=2.0.5.0 assembly. My solution was to separate the definitions by moving them into a new Silverlight Class Library. I don't know if this is a good practice but it works so far.

    Thanks

    Thursday, November 25, 2010 8:37 AM