繁体   English   中英

随机查看System.NotSupportedException:WebRequest.GetCreator中的http(字符串前缀)

[英]Randomly seeing System.NotSupportedException: http in WebRequest.GetCreator(string prefix)

在我们运行在mono上的ASP MVC应用程序中,我们有时会在创建WebRequests时获得此NotSupportedException:http。 这是堆栈跟踪:

979: Message: System.NotSupportedException: http
980:  at System.Net.WebRequest.GetCreator (System.String prefix) [0x00000] in <filename unknown>:0 
981:  at System.Net.WebRequest.CreateDefault (System.Uri requestUri) [0x00000] in <filename unknown>:0 


Version Information: 3.0.12 (master/b39c829 Tue Jun 18 11:23:32 CEST 2013); ASP.NET Version: 4.0.30319.17020

https://github.com/mono/mono/blob/master/mcs/class/System/System.Net/WebRequest.cs#L479

有时它有效,有时它不起作用。 我无法弄明白为什么。 有人解决了这个问题吗?

我在一些早期版本的Mono 2.10(几年前实际上)中看到了这一点,并帮助追踪它(但我现在还没有看到它)。

如果我的记忆没有让我失望,那么ASP.Net的启动路径或ASP.Net正在使用的同步原语中的错误都是竞争条件。

跟踪它是相当棘手的,它只发生在生产服务器上(当然)只是零星地发生。

在我的情况下,它只发生在ASP.Net重启后。 我有机器人周期性地连接到服务器,如果服务器已经停机一段时间,一旦它回来,会有很多机器人焦急地敲击服务器,显然使竞争条件更容易触发。

为了缩小范围我从源代码构建了Mono并添加了Console.WriteLine语句。 过了一段时间(事实上几个星期,因为我添加的Console.WriteLines越多越难以重现),就找到了罪魁祸首。 不幸的是,我不记得确切的问题和解决方案是什么。

希望这可以帮助您追踪它。

这是我在我们的应用程序中用来解决这个问题的hack:

private static HttpWebRequest CreateWebRequest(Uri uri)
    {
        //Webrequest creation does fail on MONO randomly when using WebRequest.Create
        //the issue occurs in the GetCreator method here: http://www.oschina.net/code/explore/mono-2.8.1/mcs/class/System/System.Net/WebRequest.cs

        var type = Type.GetType("System.Net.HttpRequestCreator, System, Version=4.0.0.0,Culture=neutral, PublicKeyToken=b77a5c561934e089");
        var creator = Activator.CreateInstance(type,nonPublic:true) as IWebRequestCreate;
        return creator.Create(uri) as HttpWebRequest;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM