Getting runtime version of a Silverlight assembly

隐身守侯 提交于 2019-11-30 07:59:51
James Campbell
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.

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.

You can use

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