c# - 使用 MVVMLight 5.0 的 ASP.NET 站点中出现 INotifyPropertyChanged、System.ObjectModel 错误

标签 c# asp.net mvvm-light

我刚刚尝试更新针对 MVVMLight 5.0 之前版本(4.4.32.1 nuget 包)运行的 ASP.NET 4.5 站点以使用 5.0.2。

现在在 visual studio 中一切都可以正常编译,但我在第一个页面 View 中遇到错误。本质上是这样的:

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'.

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

public class _Page_Views_Account_Development_cshtml : 
             MyNamespace.Web.Views.BaseView<IEnumerable<MyNamespace.Data.Models.User>> {

这是详细的编译器输出:

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)

项目层次结构本质上是:

  • “网络”引用“核心”和“数据”
  • “数据”引用“核心”
  • 所有三个项目都引用了 MVVMLight 5.0“仅限库”nuget 包。

所有三个项目都以 .NET Framework 4.5.2 为目标。

有趣的是,System.ObjectModel 似乎并不真正存在/起作用。当我尝试通过 Visual Studio 添加引用时,它没有列在程序集或扩展选项卡中。我可以在 Reference Assemblies 的 Facades 文件夹中挖掘它,但该程序集仅包含一堆东西的 TypeForwardedTo 程序集属性(包括 INotifyPropertyChanged)。此外,将 Facades 程序集添加为对我的项目的引用并没有消除错误。

有什么想法吗?

最佳答案

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

我猜有“编译时间”(当您在 VS 中点击构建时),然后是“运行时编译时间”(当您运行 ASP.NET 应用程序并首次编译 View 时)。问题在于后者。

为了修复它,您需要像这样在 web.config 中添加引用:

 <compilation>
      <assemblies>
        ...
        <add assembly="System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        ...
      </assemblies>
    </compilation>

然后在编译网页时就可以使用了。

关于c# - 使用 MVVMLight 5.0 的 ASP.NET 站点中出现 INotifyPropertyChanged、System.ObjectModel 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26977427/

相关文章:

c# - 从类似字符串的xml中提取节点值C#

c# - 为什么当变量有值时会报告 "null reference"?

c# - 在 C# 中对 DataTable 进行排序

windows-phone-7 - 未声明的前缀。如何在 Windows Phone 中声明?

mvvm - WPF V4 - MVVM Light V4 (BL16 - Mix11) - RelayCommand - CanExecute 不触发

wpf - MVVM Light 和 MVVM 有什么区别?

c# - 如何使用XDocument读取csproj文件?

c# - 如何加快加载启动画面

c# - 如何将路由参数注入(inject)_Layout.cshtml

asp.net - 日期格式和在 vb.net 中添加一天