Incompatibilities between Prism 5 and NET 4.5.2

Jul 23, 2014 at 10:32 AM
Hi,

I'm using Prism 5.0.0 with MEFExtensions in a project which is targeted for the .NET-Framework 4.5.2.
When I create a ViewModel by inheriting from BindableBase or when I use the DelegateCommand, my project no longer compiler for it fails to resolve types.
When I use DelegateCommand for example, I get the following error:

The type 'System.ComponentModel.INotifyPropertyChanged' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Regards,
Markus Palcer
Aug 1, 2014 at 2:14 PM
Hi Markus,

I have the same problem. Did you find a solution for it already?

Regards,
Patrick
Aug 4, 2014 at 7:09 AM
Hi Patrick,

I downloaded the PRISM source to check out the reason and found out that while most of the projects are Built for .NET 4.5.1 and can simply be switched, a few of them have been configured for multiple target platforms.
I can only assume that those are portable class libraries since I've never worked with those before
Although you can choose the version of the .NET-Framework, you can only choose a version up to 4.5.1.
Again I assume this is because 4.5.2 is not available for PCL's yet (anyone correct me if I'm wrong).

Anyway there are two ways to fix this, both not really satisfying.
  1. Of course you can simply switch over to .NET Framework 4.5.1 - it's what we did with gritting teeth. Thus you will still use the NuGet provided packages and benefit from the updating mechanism it provides.
  2. You can download the source and set the Projects to compile for 4.5.2.
I've tried the second approach too, since it didn't take much time. It does take some meddling with the .csproj-Files of the projects which are set to have multiple Targets in order to be able to select 4.5.2 as single target. Also you need to add some references to them, but you will see them alright if you try to compile.
Mainly you'll want to remove the content of the TargetFrameworkProfile-Tag and the whole ProjectTypeGuids-Tag. Plus in order to get it to compile you want to change the import at the end from <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" /> to <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

But on the other hand that means you either can't update PRISM or you need to apply these patches for each update (which you get by updating the sources manually) and recompile yourself until 4.5.2 is supported out of the box.

Regards,
Markus
Aug 4, 2014 at 8:01 AM
HI Markus,

Thanks for the answer.

Still I find it strange that we get this error because 4.5.2 should be backwards compatible with 4.5.1.
So I like to know from the dev team why it's complaining about it.

The errors I'm getting are a little different. But I'm using the DelegateCommand<T>

first error is - The type 'System.Windows.Input.ICommand' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.ObjectModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
second error is - The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

We don't use Nuget to update the files so I can recompile the sources. That's an options for us.

Regards,
Patrick
Aug 4, 2014 at 11:35 AM
Hi Markus,

The problem was reported on connect for referencing a pcl.
http://connect.microsoft.com/VisualStudio/feedback/details/873446/project-targeting-4-5-2-fails-to-build-when-referencing-a-pcl

The fix can be downloaded here http://www.microsoft.com/en-us/download/details.aspx?id=42637

After installation of the developer pack the building works fine.

Regards,
Patrick
May 7, 2015 at 10:17 PM
Hello people,

I got the same error, but only in the function "Edit and Continue" Visual Studio 2013. This occurs whenever I change the code and try to continue running. After much searching and downloading the source code Prism V5, I realized that libraries were created with the template portable project.

I created a simple console application that one a portable library and got the same result, ie could not change the code and continue its execution because the project was using a portable library.

Well, so far, got no choice but to rebuild the libraries without using Prism portable project.

Regards,
Gilberto W. Alexandre
May 8, 2015 at 1:32 PM
Well, as Patrick said, the problem is caused when using PCL (Portable Class Library) or, as I mentioned, "portable project". Once you reference the libs folder "C: \ Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.XXX\Facades\" as calls for the implementation, the problem was solved!

Thank you!