使用MVVMLight 5.0的ASP.NET站点中的INotifyPropertyChanged,System.ObjectModel错误

Tim*_*Tim 2 c# asp.net mvvm-light

我只是尝试更新我运行的MV 4.5M版本的MVVMLight(4.4.32.1 nuget包)的ASP.NET 4.5站点以使用5.0.2.

现在一切都在visual studio中编译得很好,但是在第一页视图中出现错误.基本上是这样的:

CS0012:类型'System.ComponentModel.INotifyPropertyChanged'在未引用的程序集中定义.您必须添加对程序集'System.ObjectModel,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'的引用.

它在编译我的一个观点时发生:

public class _Page_Views_Account_Development_cshtml : 
             MyNamespace.Web.Views.BaseView<IEnumerable<MyNamespace.Data.Models.User>> {
Run Code Online (Sandbox Code Playgroud)

这是详细的编译器输出:

c:\Users\MyName\AppData\Local\Temp\Temporary ASP.NET Files\root\f7cc8ed7\c7cafde5\App_Web_development.cshtml.5f83eb8c.uumj7lsy.0.cs(34,18): error CS0012: The type 'System.ComponentModel.INotifyPropertyChanged' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
c:\Users\MyName\AppData\Local\Temp\Temporary ASP.NET Files\root\f7cc8ed7\c7cafde5\assembly\dl3\e7e549bd\cb383382_bafecf01\GalaSoft.MvvmLight.DLL: (Location of symbol related to previous error)
c:\Users\MyName\AppData\Local\Temp\Temporary ASP.NET Files\root\f7cc8ed7\c7cafde5\assembly\dl3\031e1123\6f936e46_8202d001\MyNamespace.Core.DLL: (Location of symbol related to previous error)
c:\Users\MyName\AppData\Local\Temp\Temporary ASP.NET Files\root\f7cc8ed7\c7cafde5\assembly\dl3\625906e6\c7417347_8202d001\MyNamespace.Data.DLL: (Location of symbol related to previous error)
Run Code Online (Sandbox Code Playgroud)

项目层次结构基本上是:

  • "Web"引用"核心"和"数据"
  • "数据"引用"核心"
  • 这三个项目都引用了MVVMLight 5.0"Libraries Only"nuget包.

这三个项目都以.NET Framework 4.5.2为目标.

有趣的是,System.ObjectModel它似乎并不存在/工作.当我尝试通过Visual Studio添加引用时,它未在"程序集"或"扩展"选项卡中列出.我可以在参考装配体的Facades文件夹中进行挖掘,但该装配只包含TypeForwardedTo许多东西(包括INotifyPropertyChanged)的装配属性.此外,添加Facades程序集作为我的项目的参考不会消除错误.

有什么想法吗?

Tim*_*Tim 6

我想出了答案.ASP.NET处理可移植类库的方式与其他程序集略有不同.由于MVVMLight 5.0将所有"仅库"的nuget包切换为PCL,这引入了我处理ASP.NET处理PCL的不同方式,而以前不是问题.

我猜有"编译时间"(当你在VS中编译时),然后是"运行时编译时间"(当你运行ASP.NET应用程序并且它第一次编译视图时).问题在于后者.

为了解决这个问题,你需要在web.config中添加引用,如下所示:

 <compilation>
      <assemblies>
        ...
        <add assembly="System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        ...
      </assemblies>
    </compilation>
Run Code Online (Sandbox Code Playgroud)

然后它将在网页编译时可用.