2

We have a Portable Class Library targeting 4.0. A WPF application references this which is a standard .NET 4.0 app.

The PCL references the System.Net.NetworkCredential class.

When we build the .NET 4.0 app we get an error:

The type 'System.Net.NetworkCredential' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.

Several posts say to install KB2468871. That doesn't apply/change things.

If we add an assembly reference to "System.Net 4.0.0.0" in the app then the error changes:

Reference to type 'System.Net.NetworkCredential' claims it is defined in 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Net.dll', but it could not be found...

Of course NetworkCredential is not in System.Net, it is in the System assembly.

If I retarget to 4.5 everything works, but we need to use 4.0.

Any ideas? Thanks.

Scott Wylie
  • 4,725
  • 2
  • 36
  • 48
user1867382
  • 414
  • 3
  • 13
  • I can repro this with VS2013 and .NET 4.5.1. You can report this at connect.microsoft.com – Hans Passant Nov 12 '13 at 19:41
  • Created bug report 808382 with simplest of samples for download. Would still be good if people have workarounds. https://connect.microsoft.com/VisualStudio/feedback/details/808382/portable-class-library-unusable-you-must-add-a-reference-to-assembly-system-net-version-2-0-5-0 – user1867382 Nov 12 '13 at 21:11

1 Answers1

1

KB2468871 enables portable libraries to run on 4.0, it does not enable them to build in Visual Studio.

The first error should go away if you add a reference to System.Net, 4.0.0.0. If it does not, then you're machine is missing a required patch.

If are using:

Visual Studio 2010

You need to install Portable Library Tools: http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981/. This will install a patch that will make this work.

Visual Studio 2012 or Visual Studio 2013

This should work out of the box, if not, then you install is likely in an incomplete state. Try repairing your installation.

David Kean
  • 5,722
  • 26
  • 26