Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Razor视图中foreach循环中的程序集未引用编译错误_C#_Asp.net Mvc_Razor_Collections_Iis Express - Fatal编程技术网

C# Razor视图中foreach循环中的程序集未引用编译错误

C# Razor视图中foreach循环中的程序集未引用编译错误,c#,asp.net-mvc,razor,collections,iis-express,C#,Asp.net Mvc,Razor,Collections,Iis Express,编辑:我已经检查并尝试了SE上发现的许多其他未引用的程序集问题,但我没有发现许多涉及应该是内置程序集的问题(System.Collections.Generic.List)。这使得手动添加或删除引用等变得困难 我正在尝试从API响应构建PartialView。我已确认响应正确且格式良好,我的对象正在正确构建,但当我生成部分视图时,会显示编译错误 Compiler Error Message: CS0012: The type 'System.Collections.Generic.List`1&

编辑:我已经检查并尝试了SE上发现的许多其他未引用的程序集问题,但我没有发现许多涉及应该是内置程序集的问题(
System.Collections.Generic.List
)。这使得手动添加或删除引用等变得困难

我正在尝试从API响应构建PartialView。我已确认响应正确且格式良好,我的对象正在正确构建,但当我生成部分视图时,会显示编译错误

Compiler Error Message: CS0012: The type 'System.Collections.Generic.List`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
其中Status是一个枚举。在将模型对象传递到PartialView之前,我已经在调试中检查过模型对象是否正确且格式良好,但是我得到的不是正确的布局,而是服务器错误屏幕和500响应

在第
@foreach行(Model.Metrics中的数据度量)

完整性行动代码:

public ActionResult ComponentDetail(string id)
        {
            var data = Client.GetComponentData(id.DecodeBase64ToString());
            var partialViewResult = PartialView("_ComponentDetail", data);
            return partialViewResult;
        }

我已经弄明白了,而且非常简单。我仍然不知道为什么有必要这样做,但是在
web.config
中添加一个新的
assembly
标记似乎已经解决了这个问题。我添加的标签位于
标签下,如下所示:

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


简单,但已解决错误,视图现在可以正确渲染。

这是因为Razor引擎中添加了引用。
此问题已被报告。

我最近也遇到过同样的问题,这里最好描述一下:

问题来自PartialView.cshtml和MainView.cshtml中的两个不同引用,每个引用的是Razor页面中的两个不同类;交叉点是两个视图中的foreach循环

解决方案是再添加一行:

<add assembly="NameOfTheProject.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>


在“视图”文件夹下的Web.config中已经存在的程序集信息。

可能重复@Bjørn RogerKringsjå我添加了一个编辑解释,但我认为与许多其他“未引用”SE问题相比,这里的挑战在于,他们主要处理a)ReSharper“无法解决符号”错误(不使用R#),或b)用户库,与内置类型列表相反。您是否尝试使用System.Collections.Generic添加
?对我有用。谢谢!请注意,您需要用
包围
注释。像这样:
`
在我的例子中
<assemblies>
    <add assembly="System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
<add assembly="NameOfTheProject.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>