简体   繁体   中英

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

The PCL is used across multiple devices and projects however, I now need to integrated it into an MVC 4.5 web application.

I can access some of the objects that are directly defined inside the PCL from Razor, but this one has been stumped; I have an object that has a property like this

public List<AnotherPCLObject> AnotherPCLObjectList {get;set;}

When I try to access the property, I get a CS0012 error; the type List<> 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'.

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.

  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.

  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.

<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. Intellisense wasn't working for a few assemblies related to Linq extensions so I had to add a reference for System.Core.

Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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