.net - ObservableCollection-无法实现,因为它没有匹配的返回类型

我有两个项目。
第一个是带有下一个界面的Wpf Project(FrameWork 3.5):

public interface View
{
    ObservableCollection<int> Items { set; }  
}

和测试项目(FrameWork 4.0)
public class ViewFake:View
{
    public ObservableCollection<int> Items
    {
        set { throw new NotImplementedException(); }
    }
}

我收到此错误:

ViewFake' does not implement interface member 'View.Items'. 'ViewFake.Items' cannot implement 'View.Items' because it does not have the matching return type of 'System.Collections.ObjectModel.ObservableCollection`1'.



我看了两个版本中ObservableCollection的位置,以及
  • [FrameWork 4.0] - System.dll
  • [FrameWork 3.5] - WindowsBase.dll

  • 因此,唯一的解决方案是升级主项目或降级测试项目?

    最佳答案

    如果我没记错的话,ObservableCollection是位于.NET 3.5的System.Windows。*命名空间中,只有在4.0中,它才移至System.Collections.ObjectModel命名空间。

    * update:更改的不是 namespace ,而是程序集。但是结果是相同的:.NET认为它是不同的类型,因为包含的程序集是类型信息的一部分。

    这里更大的问题是您的测试和被测试的类正在使用不同的.NET Framework版本和不同版本的Common Language Runtime。那可能会流下眼泪。您的项目可以使用相同的版本吗?

    https://stackoverflow.com/questions/12011044/

    相关文章:

    visual-studio-2010 - USBView编译错误

    c# - 第一次使用msbuild

    c# - 较少严格的CodeDomProvider来编译DLL

    c# - 简单的代理asp.net错误

    actionscript-3 - 在函数外部使用变量。错误-参数数目不正确。预期1

    compiler-errors - 未在此范围内声明“RUSAGE_THREAD”

    cocos2d-iphone - 在Xcode中禁用Apple Mach-o链接器错误

    android - 编译应用程序时出现LogCat错误

    windows - libqxt编译-mingw32-make异常

    matlab - 在matlab中创建一个exe文件的问题