Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting runtime version of a Silverlight assembly

I want to show my Silverlight 3 application's version number in the about box, but when I use a traditional .Net call like:

Assembly.GetExecutingAssembly().GetName().Version; 

I get a MethodAccessException on the GetName() call. How am I supposed to get the version number of my assembly?

like image 896
Dov Avatar asked Feb 19 '10 15:02

Dov


2 Answers

private static Version ParseVersionNumber(Assembly assembly) {     AssemblyName assemblyName = new AssemblyName(assembly.FullName);     return assemblyName.Version; } 

or this:

Assembly assembly = Assembly.GetExecutingAssembly();  String version = assembly.FullName.Split(',')[1]; String fullversion = version.Split('=')[1];  

From: http://betaforums.silverlight.net/forums/p/128861/288595.aspx

a post about it:

http://forums.silverlight.net/forums/p/93400/214554.aspx

You can look at the js file I posted here: Detect Silverlight version required by an assembly

Your error is expected.as it is secutiry critical, above are some work arounds.

like image 128
James Campbell Avatar answered Oct 02 '22 07:10

James Campbell


GetName is marked as Security Critical and hence you get an exception when you attempt to call it.

You will need to use the FullName property and parse out the Version=x.x.x.x part of the string.

like image 43
AnthonyWJones Avatar answered Oct 02 '22 08:10

AnthonyWJones