views:

214

answers:

1

I am trying to send data to DotNetOpenAuth website as described here http://msdn.microsoft.com/en-us/library/debx8sh9.aspx Sender receive (500) Internal Server Error. The same code for blank website without DotNetOpenAuth works fine. Should I tweak something?

Here is an exception:

System.ArgumentNullException was unhandled by user code
  Message="Value cannot be null.\r\nParameter name: key"
  Source="mscorlib"
  ParamName="key"
  StackTrace:
       at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
       at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
       at DotNetOpenAuth.OAuth.ChannelElements.OAuthChannel.ReadFromRequestCore(HttpRequestInfo request) in c:\BuildAgent\work\7ab20c0d948e028f\src\DotNetOpenAuth\OAuth\ChannelElements\OAuthChannel.cs:line 145
       at DotNetOpenAuth.Messaging.Channel.ReadFromRequest(HttpRequestInfo httpRequest) in c:\BuildAgent\work\7ab20c0d948e028f\src\DotNetOpenAuth\Messaging\Channel.cs:line 372
       at DotNetOpenAuth.OAuth.ServiceProvider.ReadRequest(HttpRequestInfo request) in c:\BuildAgent\work\7ab20c0d948e028f\src\DotNetOpenAuth\OAuth\ServiceProvider.cs:line 222

Exception occurs on last line of the code:

    private void context_AuthenticateRequest(object sender, EventArgs e)
    {
        // Don't read OAuth messages directed at the OAuth controller or else we'll fail nonce checks.
        if (this.IsOAuthControllerRequest())
        {
            return;
        }

        if (HttpContext.Current.Request.HttpMethod != "HEAD")
        { // workaround: avoid involving OAuth for HEAD requests.
            IDirectedProtocolMessage incomingMessage = OAuthServiceProvider.ServiceProvider.ReadRequest(new HttpRequestInfo(this.application.Context.Request));
+1  A: 

If you're sending the POST request with a Content-Type of application/x-www-form-urlencoded, but the POST entity contains something other than the normal key1=value1&key2=value2 format, that might explain it. It looks like DotNetOpenAuth can't handle a POST entity that claims to be name=value pairs but only has a value without a key in front of it. Arguably that's a bug in DotNetOpenAuth since normally that's just considered a value of a null key.

If you're not sending key=value pairs at all, I suggest you drop or change the Content-Type header so that you're not claiming to be sending key=value pairs. If you are sending them, but intentionally sending a null key, then hang on while the bug gets fixed.

Andrew Arnott