15

I'm having a problem with assembly resolution on an end-user machine and I believe it's related to using Portable Class Libraries....

I have a .NET 4.0 application that was originally written in Visual Studio 2010. Recently we upgraded to Visual Studio 2012 and we've created a few projects that are Portable Class Libraries. I don't believe we need these features now, but we're also building a Windows 8 Store application that might benefit from these libraries.

When I compile my project, what exactly does the portable library feature do? I expect that it allows me to run it on different frameworks without modification or recompiling.

When I look at the library in reflector dotPeek it shows the Platform attribute as:

.NETPortable,Version=v4.0,Profile=Profile5

And the references seem 2.0-ish:

mscorlib, Version=2.0.5.0

System, Version=2.0.5.0

System.Runtime.Serialization, Version=2.0.5.0

When I run the application on this end-user's machine, I see an error in the log file:

Could not load file or assembly, 'System.Core, Version=2.0.5.0...'

Googling System.Core 2.0.5.0 seems to refer to SilverLight -- which appears to be one of the targeted frameworks.

This machine does not have Visual Studio installed, but has .NET 4.0 (4.0.3 update)

Is there something I should be doing differently to compile, something I should investigate in my dependencies or something I should be looking to install on the end-user machine? What does the 2.0.5.0 refer to?

Community
  • 1
  • 1
bryanbcook
  • 16,210
  • 2
  • 40
  • 69
  • 2.0.5.0 is the target version for PCL, it gets remapped by the framework. Profile5 = Framework 4.0 and Store. Long shot: Store apps require .NET 4.5. Watch out for the Client profile of 4.0 – Hans Passant Dec 14 '12 at 01:33

1 Answers1

18

For .NET 4, you need an update (KB2468871) for Portable Class Libraries to work. From the KB Article:

Feature 5

Changes to the support portable libraries. These changes include API updates and binder modifications. This update enables the CLR to bind successfully to portable libraries so that a single DLL can run on the .NET Framework 4, on Silverlight, on Xbox, or on the Windows Phone. This update adds public Silverlight APIs to the .NET Framework 4 in the same location. The API signatures will remain consistent across the platform. All modifications are 100 percent compatible and will not break any existing code.

Also see the "Deploying A .NET Framework App" section of the MSDN Portable Class Library Documentation.

EDIT: Actually, if the machine has .NET 4.0.3 installed as you mention, that should be sufficient. Can you double-check to make sure that it is actually installed?

Daniel Plaisted
  • 16,674
  • 4
  • 44
  • 56
  • Very strange. I downloaded http://www.microsoft.com/en-us/download/details.aspx?id=29053 (KB2600211 published 03/04/12) but when I executed it said it was "blocked" or already installed. I downloaded KB2468871 (published 6/08/11)and was able to install without issue. The app now works. – bryanbcook Dec 14 '12 at 15:46
  • 1
    I still get this error with both update saying "does not apply to your system". This is with VS 2012. Sigh. – Mark Sowul Jun 17 '13 at 16:46
  • Looks like the compiler has some glitches with the PCLs, for my issue: https://connect.microsoft.com/VisualStudio/feedback/details/780023/xaml-designer-throws-nullreferenceexception-object-reference-not-set-to-an-instance-of-an-object-sometimes-for-mvvm, https://connect.microsoft.com/VisualStudio/feedback/details/779370/vs2012-incorrectly-resolves-mscorlib-version-when-referencing-pcl-assembly – Mark Sowul Jun 17 '13 at 17:13
  • We had a machine with .NET 4.0.3 installed and still encountered this error. Installing KB2468871 fixed it. – Oran Dennison Aug 13 '14 at 23:12
  • 1
    KB2468871 does not apply to Windows 8 or 8.1, however I'm seeing this issue during compilation of a VS project on a Windows 8.1 machine. – RJ Cuthbertson Jul 16 '15 at 21:53
  • Still an issue... New Windows 10 machine, .NET 4.8 installed, References to System.Core.2.0.5 do not resolve - KB2468871 is blocked, all attempts to install .Net 4.0 are also blocked.... Dead in the water. – David V. Corbin Feb 18 '21 at 11:20