Tuesday, October 23, 2012

Issues / Bugs with Assembly References in Portable Class Library Projects

As we know that a portable class library can only reference other portable library projects. For this example, we are using Portable Library Tools 2 Extension installed through Extension Manager in Visual Studio 2010.

There seem to be two rules for assembly / project references in a portable class library project.
  1. Portable Class Library Project can only reference other portable class library projects / assemblies.

  2. The project where the reference is being added must have compatible set of framework selection as the project / assembly whose reference is being added. This compatibility is difficult to understand. Basically the available features set of the source assembly / project must be same or smaller than the target project. This happens when the source project / assembly is either targeting the same set of frameworks or has more framework selections than the target portable class library project.
There are two issues with assembly references in Portable Class Library Project.

No Checks for Portable assembly references:
The only verification for assembly references seem to be that the source assembly must be a portable library. It doesn't seem to verify the platform selection of the source assembly.

Let's look at the sample solution with two portable class library projects as follows:

The platforms selection of the PortableSourceLibrary and PortableTargetLibrary is as follows:

From the platform selection it is apparent that PortableSourceLibrary is targeting a bigger subset of features than the PortableTargetLibrary project. Based on the rules discussed above, a reference of PortableClassLibrary project can be added to the PortableSourceLibrary project.

For the same reason vice versa is not true i.e. when we try to add a reference of PortableSourceLibrary into PortableTargetLibrary, the IDE doesn't allow so and shows the error notification dialog. But when we try to add the assembly reference instead of the project reference, it doesn't show the same behavior.

And it silently adds the reference.

This is definitely a different behavior than the project reference and it needs to be requested to be fixed.

No Verification when the target platforms for source portable library project is updated:
Portable Class Library project checks whether the source portable library project has the compatible platforms selection as the current project. But it seem that this is only checked when the reference is being added. Once the reference is added then we can change it to an incompatible platforms selection and this would still build fine.

Let's again add PortableTargetLibrary project reference into PortableSourceLibrary project.

Now select the PortableTargetLibrary project and update the target frameworks as follows:

Now this is the combination which would be an issue if we add a fresh reference of this project to PortableSourceLibrary project. But there doesn't seem to be any issue now when the reference is already added.

Please note that the project having the references does report issues when we unload the project and try to load it again. We can't load it unless we update the target platforms for the source project being referenced.

I have reported the issue on Microsoft Connect. Please vote for this.



No comments: