3

Wanted to connect with the Withings API. I used the same Controller in an other project, where he worked perfectly. In a project where the site is an Azure webrole(don't know how that is the issue) it just doesn't work. First I got

The type initializer for 'DotNetOpenAuth.Reporting' threw an exception.

So I turned it off in the web.config

reporting enabled="false"

Now I got

The type initializer for 'DotNetOpenAuth.Logger' threw an exception.

I don't use log4net.

 public ActionResult StartOAuth()
    {

        var serviceProvider = GetServiceDescription();
        var consumer = new WebConsumer(serviceProvider, _tokenManager);

        // Url to redirect to
        var authUrl = new Uri(Request.Url.Scheme + "://" + Request.Url.Authority + "/Withings/OAuthCallBack");

        // request access
        consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(authUrl, null, null));

        // This will not get hit!
        return null;
    }

private ServiceProviderDescription GetServiceDescription()
    {
        return new ServiceProviderDescription
        {
            AccessTokenEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/access_token", HttpDeliveryMethods.PostRequest),
            RequestTokenEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/request_token", HttpDeliveryMethods.PostRequest),
            UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/authorize", HttpDeliveryMethods.PostRequest),
            TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
            ProtocolVersion = ProtocolVersion.V10a
        };
    }
saggu
  • 73
  • 5
Łukasz Młynik
  • 642
  • 8
  • 24

1 Answers1

7

So it turns out it was Azure's fault. In web.config there is a section which broke DotnetOpenAuth. Deleting this section is a workaround. Probably adding log4net would also fix this issue, but I didn't test.

<trace> 
<listeners> 
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics"> 

<filter type="" /> 
</add> 
</listeners> 
</trace>
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
Łukasz Młynik
  • 642
  • 8
  • 24
  • Wow. Thanks for sharing. If you could also try with the error repro'ing, and capture the exception details so we know what exactly went wrong (you may have to look in the InnerException) I'd be most interested to hear your findings. – Andrew Arnott Apr 18 '12 at 14:07
  • The inner exception is `{"Could not create Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35."}` – Łukasz Młynik Apr 20 '12 at 16:23