views:

392

answers:

2

How can I tell whether Silverlight 2 is sufficient for an assembly or Silverlight 3 is required?
I have all information that is available through reflection (Mono.Cecil).

Same question for SL 3 versus 4.

Thanks in advance.

+1  A: 

You cannot tell from just the class library and its metadata - this can only be reliably determined from a Silverlight application's embedded manifest file in the .Xap.

Jeff Wilcox
So if new features of Silverlight 3 are not used, SL3 assembly can be referenced and used by SL2 applications? Is this the same for SL4 assemblies?
Andrey Shchekin
A: 

This might be exactly what you are looking for:

Assembly asm = Assembly.GetExecutingAssembly(); 
string[] parts = asm.FullName.Split(',');
string version = parts[1];

http://forums.silverlight.net/forums/p/23321/82774.aspx#82774

4 is backward compatible with 3, 3 is backward compatiable with 2.

You should know which version of silverlight the app is built in.

Installation and detection:

This one has a Javascript file that will detect if SL is installed and What version: http://blog.mdk-photo.com/post/Detecting-Silverlight-version-installed.aspx

http://www.apijunkie.com/APIJunkie/blog/post/2009/04/How-to-programmatically-detect-Silverlight-version.aspx

http://stackoverflow.com/questions/20722/version-detection-with-silverlight

http://www.scribd.com/doc/14938624/Creating-a-Custom-Silverlight-Installation-Experience

http://blogs.msdn.com/tims/archive/2007/10/29/optimizing-the-silverlight-install-experience.aspx

Thge GAC will also notify you durring compile if you are running the wrong version of SL. Typically when you have Silverlight tools installed and try to compile an app. For instance your assembly is created in version 3 and you use a control that is only available in 3, you will have to have SL 3 tools installed or the build will error letting you know.

More on the Silverlight assemblies:

http://www.netfxharmonics.com/2008/12/Reusing-NET-Assemblies-in-Silverlight

http://nerddawg.members.winisp.net/AssemblySniffer/

James Campbell
I don't think these links answer the question, because first one is about SL runtime as a whole, and the second one does not help with the version. Backward compatibility by definition means that SL4 allows SL3 libs, but does SL3 allow SL4 libs?
Andrey Shchekin
they are only backward compatable. 3 does not support four and two does not support three. In the case a newer version is required you can detect the version and force an install.
James Campbell
But how I detect version based on the assembly alone? I do not want to install SL since it is an assembly analysis question. SL might not be installed at all.
Andrey Shchekin
I will update my answer with how the install and detection process works. Also note most users are auto notified when a new version is released and get a notification to install update, most silverlight users have 3.0 installed.
James Campbell
First link has a js file which can detect if sl is installed and what version.
James Campbell
I added code to check version directly at the assembly level.
James Campbell
This checks the version of the assembly set by [assembly: AssemblyVersion] attribute, not the required version of the Silverlight runtime. I can't use JS because I am essentially doing an assembly analytics tool which runs on server and not on the client. And AssemblySniffer shows only Silverlight yes/no instead of specific version.
Andrey Shchekin