简体   繁体   English

引用ASP.NET 4.5 MVC中的可移植类库(PCL)会给出有关List <>的错误

[英]Reference a Portable Class Library (PCL) from ASP.NET 4.5 MVC gives error about List<>

I am having lots of issues trying to access some of the objects that are present/referenced inside a portable class library that has the targets of: 我在尝试访问具有以下目标的可移植类库中存在/引用的一些对象时遇到很多问题:

.NET Framework 4.5 ASP.NET Core 5.0 Windows 8 Windows Phone Silver Light 8 Xamarin Android Xamarin iOS .NET Framework 4.5 ASP.NET Core 5.0 Windows 8 Windows Phone Silver Light 8 Xamarin Android Xamarin iOS

The PCL is used across multiple devices and projects however, I now need to integrated it into an MVC 4.5 web application. PCL用于多个设备和项目,但是,我现在需要将其集成到MVC 4.5 Web应用程序中。

I can access some of the objects that are directly defined inside the PCL from Razor, but this one has been stumped; 我可以从Razor访问PCL内部直接定义的一些对象,但是这个对象已经被树桩了。 I have an object that has a property like this 我有一个具有这样属性的对象

public List<AnotherPCLObject> AnotherPCLObjectList {get;set;} 公共列表<AnotherPCLObject> AnotherPCLObjectList {get; set;}

When I try to access the property, I get a CS0012 error; 当我尝试访问该属性时,出现CS0012错误。 the type List<> is defined in an assembly that is not referenced. List <>类型是在未引用的程序集中定义的。 You must add a reference to assembly 'System.Collections, Version 4.0.0.0, Culture neutral, PublicKeyToken=b03f5f7f11d50a3a'. 您必须添加对程序集“ System.Collections,版本4.0.0.0,与文化无关,PublicKeyToken = b03f5f7f11d50a3a”的引用。

Searching around, it looks like this should be in the standard set of assemblies that I have referenced, which leads me to believe that there is some sort of magic assembly mapping that is needed? 到处搜索,看起来这应该在我所引用的标准程序集中,这使我相信需要某种魔术程序集映射?

So here are the questions: 所以这是问题:

  1. is there a way to add ASP.NET 4.5 as a target, I hunted for several hours and could not find a way. 有没有一种方法可以将ASP.NET 4.5添加为目标,我狩猎了几个小时却找不到方法。

  2. How do I reference the missing assembly, when there is no System.Collections assembly to be found in any of the reference assembly directories. 当在任何参考程序集目录中都找不到System.Collections程序集时,如何引用缺少的程序集。

  3. If there is some sort of magic used to map the assembly, where is that documented? 如果使用某种魔术来映射装配,那么在哪里记录?

If you're still having issues with this you should be able to resolve it by adding the assembly references to the compilation section of your web.config. 如果您仍然对此有疑问,则应该可以通过将程序集引用添加到web.config的“编译”部分中来解决该问题。

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

I had the same issue with an MVC 5.2.3 project targeting 4.6.1 that referenced a portable assembly. 对于以4.6.1为目标的MVC 5.2.3项目,它引用了一个可移植程序集,也遇到了同样的问题。 Intellisense wasn't working for a few assemblies related to Linq extensions so I had to add a reference for System.Core. Intellisense不适用于与Linq扩展有关的一些程序集,因此我不得不为System.Core添加参考。

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM