无法从我的Silverlight应用程序调用Assembly.GetName() [英] Unable to call Assembly.GetName() from my Silverlight application

查看:192
本文介绍了无法从我的Silverlight应用程序调用Assembly.GetName()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序中显示我的应用程序版本号,而要做到这一点最简单的方法就是使用的版本号集。

  VAR总成= System.Reflection.Assembly.GetExecutingAssembly(); 
变种名称= assembly.GetName();
返回的String.Format(版本{0} {1},name.Version.Major,name.Version.Minor);



我能得到执行组装没有问题,但在调用的GetName( )返回 MethodAccessException 此消息




尝试通过安全透明的方法'MainPage..ctor()来访问安全至关重要法System.Reflection.Assembly.GetName()'失败。




这是怎么回事,有什么我可以做些什么,如果不是有检索程序集版本?


解决方案

该Assembly.GetName标有性SecurityCriticalAttribute属性尝试使用 GetCallingAssembly()。全​​名和刮版本信息出来。




不要在你的应用程序中使用此成员。如果你这样做,你的代码将
抛出一个MethodAccessException。此成员是安全关键,其中
。通过Silverlight的
类库.NET框架它限制了内部使用。 [安全至关重要]




来自:的 http://msdn.microsoft.com/en-us/library/9w2wdeze(VS.95)的.aspx


I want to display my application version number within my application, and the simplest way to do this is to use the version number for the assembly.

var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var name = assembly.GetName();
return String.Format("Version {0}.{1}", name.Version.Major, name.Version.Minor);

I can get the executing assembling without problem, but the call to GetName() returns a MethodAccessException with this message

Attempt by security transparent method 'MainPage..ctor()' to access security critical method 'System.Reflection.Assembly.GetName()' failed.

Why is this happening, is there anything I can do about it, and if not is there another means of retrieving the assembly version?

解决方案

The Assembly.GetName is marked with SecurityCriticalAttribute attribute try using GetCallingAssembly().FullName and scrape the version info out of it.

Do not use this member in your application. If you do, your code will throw a MethodAccessException. This member is security-critical, which restricts it to internal use by the .NET Framework for Silverlight class library. [SECURITY CRITICAL]

from: http://msdn.microsoft.com/en-us/library/9w2wdeze(VS.95).aspx

这篇关于无法从我的Silverlight应用程序调用Assembly.GetName()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆