Silverlight 4, subclassing WebClient

百般思念 提交于 2019-12-04 10:22:30
Stephen McDaniel

WebClient's constructor is marked with the SecuritySafeCritical attribute. And it looks like that is what is causing the security exception. I tried applying that same attribute to MyWebClient's constructor but that didn't work. From what I've read, this kind of thing just isn't allowed in Silverlight. For example, see this other question.

For reference, the exact exception message is:

System.TypeLoadException

Inheritance security rules violated while overriding member: 'MyWebClient..ctor()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

I wish there was a better answer...

You need to implement a default constructor with the SecuritySafeCritical attribute. Had this problem today and that was the solution.

public class MyWebClient : System.Net.WebClient
{
    [SecuritySafeCritical]
    public MyWebClient() : base() {}
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!