Vagif Abilov's blog on .NET

Check your code portability with PCL Compliance Analyzer

I am extracting parts of my Simple.Data OData adapter to make a portable class library (PCL). The goal is to create an OData library available for desktop .NET platforms, Windows Store, Silverlight, Windows Phone and even Android/iOS (using Xamarin Mono). To study platform-specific PCL capabilities I used an Excel worksheet provided by Daniel Plaisted (@dsplaisted). It’s a very helpful document, but it would be much easier if I could simply point some tool to an assembly file and it would show its portable and non-portable calls.

I haven’t found such tool, so I wrote one. It’s called PCL Compliance Analyzer. Select an assembly file, set of platforms you want to target, and it will show you if the assembly is PCL compliant and what calls are not. Here are the results for Mono.Cecil (that I used to scan assembly calls):

MonoCecil

As you can see, only about 10% of Mono.Cecil is not portable to any of the .NET platforms.

Let’s try something completely different. Here’s RavenDB.

RavenDbAll

Note that non-portable calls include calls to third-party libraries, like NLog. This is not interesting because those third-party assemblies are subject to a separate check, and it’s reasonable to limit portability compliance check to only system API. So we check “Exclude third party libraries” check box and repeat the scan. Here’s the new result:

RavenDbNoExt

Exclusion of third-party libs reduce the number of non-portable calls from 1642 to 674. But we are targetting all platforms (even Xbox 360), and this is perhaps not a very good idea for a NoSQL database with LINQ support. If we limit supported platforms to only .NET 4.5, we will end up with this picture:

RavenDbNet45

Of course the choice of one of RavenDB files is completely random here. I just had an old project folder with files left from Rob Ashton’s workshop on RavenDB, so I used one of the assembly files to demonstrate what you can do with PCL Compliance Analyzer.

Finally, if you point it to a true PCL assembly and select right set of target platforms, PCL Analyzer will confirm that all calls are portable. Like it did in case of my Simple.OData.Client:

SimpleODataClient

PCL Compliance Analyzer is an open-source project hosted at GitHub, and if you only need its binaries, you can download them here.

Comments

wyld_sider said:

Curious about items that don't appear in the checklist, such as System.Runtime.Serialization.SerializationInfo.GetString.  I assume if it is from MS and not in the list, it isn't portable by default?

# February 11, 2013 8:19 PM

Vagif Abilov said:

Hi wyld_sider,

SerializationInfo is not in the list of portable .NET classes. A lot of more or less standard .NET classes can't be used in portable libraries.

# February 12, 2013 10:39 AM

wyld_sider said:

Perhaps a bug?  When I ran this with an assembly with Tuples, it reported it as failing, but when I looked in the spreadsheet, they were there.  Can you double check this?

# February 16, 2013 1:09 AM

Vagif Abilov said:

Hi wyld_sider,

Tuple is available not for all platforms, so it's important to check what platforms you are selecting. As long as I don't include WP7 and WP7.5 in platform set, Tuple is reported as supported.

# February 18, 2013 3:01 PM

Gleb said:

Nice post and even more useful tool, thanks!

I notice that Excel workshet doesn't have Silverlight 3 column. Is it possible to create it (I mean, it's probably a compiled data anyway)?

# March 8, 2013 2:38 PM

Gleb said:

My bad, forgot that Silverlight 3 isn't included in supported platforms list for PCL.

# March 10, 2013 9:47 PM

BSalita said:

Thanks for this tool. Will use it if Xamarin proposal gets green light from clients.

# April 25, 2013 1:58 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 7 and 8 and type the answer here: