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

StackOverflow https://stackoverflow.com/questions/17829337

  •  04-06-2022
  •  | 
  •  

On our ASP MVC application running on mono, we sometimes get this NotSupportedException: http when creating WebRequests. Here is the stacktrace:

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

Sometimes it works and sometimes it doesnt. I couldnt figure out why. Did anyone solve this issue?

有帮助吗?

解决方案 2

This is a hack I used to solve this issue in our application:

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;
    }

其他提示

I saw this in some of the earlier versions of Mono 2.10 (a couple of years ago actually), and helped tracking it down (but I haven't seen it for some time now).

If my memory doesn't fail me it was a race condition in either ASP.Net's startup path or a bug in the synchronization primitives ASP.Net was using.

It was fairly tricky to track it down, it only happened on the production server (of course) and only sporadically.

In my case it only happened after an ASP.Net restart. I had bots connecting periodically to a server, and if the server had been down for some time there would be many bots anxiously pounding the server once it got back, apparently making the race condition easier to trigger.

In order to narrow it down I built Mono from source and added Console.WriteLine statements. After a while (weeks in fact, since the more Console.WriteLines I added the harder it became to reproduce), the culprit was found. Unfortunately I don't remember exactly what the problem nor the fix was.

Hopefully this will help you track it down.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top