Getting runtime version of a Silverlight assembly

本小妞迷上赌 提交于 2019-11-29 10:53:42

问题


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?


回答1:


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.




回答2:


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.




回答3:


You can use

Assembly.GetExecutingAssembly()
 .GetCustomAttributes(false).OfType<AssemblyVersionAttribute>()
 .Single().Version;


来源:https://stackoverflow.com/questions/2297273/getting-runtime-version-of-a-silverlight-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!