Silverlight 4,子类化WebClient [英] Silverlight 4, subclassing WebClient

查看:176
本文介绍了Silverlight 4,子类化WebClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据建议,我在几个网页上看到(例如 C#:使用CookieContainer使用WebClient类),我子类化WebClient类以使用cookie:

Following an advice, I saw at several web pages (for example C#: Using CookieContainer with WebClient class), I subclassed WebClient class to use a cookie with it:

public class MyWebClient : System.Net.WebClient
{

}

初始化MyWebClient:

Now, when I initialize MyWebClient:

MyWebClient wc = new MyWebClient();

它抛出TypeLoadException。我的操作系统是Windows 7(日语),所以错误信息不是英语;我看到它是与安全规则相关。可能有什么问题?

it throws TypeLoadException. My OS is Windows 7 (japanese), so error message is not in english; I see it is related to security rules. What might be the problem?

推荐答案

WebClient的构造函数标记为 SecuritySafeCritical 属性。看起来这是导致安全异常的原因。我尝试应用相同的属性到 MyWebClient 的构造函数,但是没有工作。从我读过的,这种事情只是不允许在Silverlight。例如,请参见此其他问题

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:


TypeLoadException

System.TypeLoadException

继承安全规则违反,而
重写成员:'MyWebClient..ctor()'。
的安全可访问性重写方法必须匹配被覆盖的
方法的安全可访问性。

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...

这篇关于Silverlight 4,子类化WebClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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