Silverlight 中继承的 WeakReference 抛出 ReflectionTypeLoadException
我正在尝试在我的 Silverlight 应用程序中使用类型安全的 WeakReference。我正在遵循此网站上的食谱:http://ondevelopment。 blogspot.com/2008/01/generic-weak-reference.html 仅使用 System.WeakReference 并省略引用序列化的内容。
当我尝试运行它时,它抛出 ReflectionTypeLoadException 并显示以下消息:
“{System.TypeLoadException:违反了继承安全规则 压倒一切的成员: 'Coatue.Silverlight.Shared.Cache.WeakReference`1..ctor()'。安全 重写方法的可访问性必须与安全性相匹配 被重写方法的可访问性。}"
这是我正在使用的代码:
using System;
namespace Frank
{
public class WeakReference<T>
: WeakReference where T : class
{
public WeakReference(T target)
: base(target) { }
public WeakReference(T target, bool trackResurrection)
: base(target, trackResurrection) { }
protected WeakReference() : base() { }
public new T Target
{
get
{
return (T)base.Target;
}
set
{
base.Target = value;
}
}
}
}
I'm trying to use a type-safe WeakReference in my Silverlight app. I'm following the recipe on this site: http://ondevelopment.blogspot.com/2008/01/generic-weak-reference.html only using the System.WeakReference and omitting the stuff that references Serialization.
It's throwing a ReflectionTypeLoadException when I try to run it, with this message:
"{System.TypeLoadException: Inheritance security rules violated while
overriding member:
'Coatue.Silverlight.Shared.Cache.WeakReference`1..ctor()'. Security
accessibility of the overriding method must match the security
accessibility of the method being overriden.}"
Here's the code I'm using:
using System;
namespace Frank
{
public class WeakReference<T>
: WeakReference where T : class
{
public WeakReference(T target)
: base(target) { }
public WeakReference(T target, bool trackResurrection)
: base(target, trackResurrection) { }
protected WeakReference() : base() { }
public new T Target
{
get
{
return (T)base.Target;
}
set
{
base.Target = value;
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 Thomas 提到的,你不能从 silverlight 中的弱引用继承,但你可以包装它:
As Thomas mentioned, you can't inherit from weak reference in silverlight but you can wrap it:
WeakReference
类存在继承需求,而 Silverlight 运行时没有必要的权限。所以你不能在Silverlight中继承WeakReference
...There is an inheritance demand on the
WeakReference
class, and the Silverlight runtime doesn't have the necessary permissions. So you can't inheritWeakReference
in Silverlight...