27

I'm trying to read a message from an Azure ServiceBus queue using an Azure WebJob but it's throwing and exception:

Unhandled Exception: System.InvalidOperationException: Found 2 DNS claims in authorization context.

I've set the correct connection strings named "AzureWebJobsServiceBus", "AzureWebJobsDashboard" and "AzureWebJobsStorage"

The WebJob Program code has been updated to use JobHostConfiguration:

class Program
{
    static void Main()
    {
        var config = new JobHostConfiguration();
        config.UseServiceBus();

        var host = new JobHost(config);
        host.RunAndBlock();
    }
}

And the actual Job method

public class Functions
{
    public async static Task ServiceBusResizeRequest(
         [ServiceBusTrigger("blah")] string message,             
         TextWriter log
         )
    {            
        await log.WriteLineAsync("got message " + message);
    }

}

I can successfully create and write to the queue via a separate console application.

But when I run the webjob application, it throws that exception.

Any ideas?

EDIT: Using .net 4.6.1

mathewc
  • 12,582
  • 1
  • 40
  • 51
sf.
  • 21,036
  • 11
  • 48
  • 57
  • Downgrading from .net 4.6.1 to 4.6 seems to prevent the issue from occuring. I'll leave this open for a bit longer to see if anyone has an answer as to why 4.6.1 fails – sf. Dec 17 '15 at 10:04
  • 2
    Well, the WebJobs SDK targets 4.5. we'll release an update moving to 4.6 soon, but that might be the issue. – mathewc Dec 17 '15 at 16:28
  • Cheers, thanks. Didn't realize it targets 4.5 only. – sf. Dec 17 '15 at 23:01
  • One of you should submit this as an answer so it's easier for the next person to find this. :) – Chris Anderson-MSFT Dec 19 '15 at 22:36
  • @ChrisAnderson-MSFT Just to note we have the same problem without the WebJobs SDK, calling Service Bus with a regular SubscriptionClient on 4.6.1. We couldn't get the AppContextSwitchOverrides fix below to work, either in the Web.config of the service making the call or the App.config of the project where our service bus client is, but a downgrade to 4.6 fixed the issue. – Jude Fisher Jan 17 '16 at 19:55
  • Odd. I sent a note to the SB team. – Chris Anderson-MSFT Jan 19 '16 at 08:11

7 Answers7

42

The answer marked as solution, is not the solution, it is a botched job. The solution to use it in .Net Framework 4.6.1 is to add in the rutime block in App.config:

<AppContextSwitchOverrides value="Switch.System.IdentityModel.DisableMultipleDNSEntriesInSANCertificate=true" />

Read this article Mitigation: X509CertificiateClaimSet.FindClaims Method

Very IMPORTANT for now Azure WebApps / WebJob etc, doesn't support 4.6.1 I will note here when (said at jan 21, 2016).

It means, that you can develop a web job application with 4.6.1, but when you push it to Azure, you can see exceptions like Job failed due to exit code -2146232576

Alberto León
  • 2,629
  • 2
  • 23
  • 23
  • 9
    Had the same problem. For some reason this AppContextSwitchOverrides setting in config did not help, so I just added the code in constructor AppContext.SetSwitch("Switch.System.IdentityModel.DisableMultipleDNSEntriesInSANCertificate", true); – Ben Jan 15 '16 at 22:02
  • Perhaps you have the Context file in different project. Have you tried to add the setting in the app.config of the application and in the project with context too? – Alberto León Jan 16 '16 at 09:17
  • I have an Azure worker role project and tried to apply this configuration to app.config section. – Ben Jan 18 '16 at 16:02
  • 2
    for us was upgraded from 4.5.2 to 4.7.2 - this solution solved the issue – Falco Dec 19 '18 at 09:53
23

January 29th Microsoft released version 3.1.3 of the NuGet package WindowsAzure.ServiceBus.

From the release notes:

• General: .Net 4.6.1+ compatibility fix. Fixing custom DNS IdentityVerifier so that we honor multiple DNS claims returned by WIF

Upgrading the package solved the problem for us.

lsmeby
  • 354
  • 2
  • 4
3

As outlined in this answer above, the snippet below does the trick

<runtime>
    ...
    <AppContextSwitchOverrides value="Switch.System.DisableMultipleDNSEntriesInSANCertificate=true" />
    ...
<runtime>

BUT be carefull to add it to the correct project in your solution! Add it to the project containing the Azure code and Azure references.

Community
  • 1
  • 1
participant
  • 2,701
  • 2
  • 20
  • 37
1

Downgrading from .net 4.6.1 to 4.6 seems to prevent the issue from occurring.

sf.
  • 21,036
  • 11
  • 48
  • 57
1

Today, I ran into this issue and had no idea about it. Finally, I decided to upgrade all the Azure nuget packages that I am using (including webjobs, servicebus ...) and BOOM! it WORKS. Hopefully, it will help if anyone runs into this issue in the future

Hung Cao
  • 2,900
  • 3
  • 16
  • 27
1

Microsoft released a new package (under a new name) to fix this issue. So ...

  • remove the Microsoft.AspNet.SignalR.ServiceBus package,
  • install the Microsoft.AspNet.SignalR.ServiceBus3 package instead, and
  • upgrade the WindowsAzure.ServiceBus package.

More info here: https://github.com/SignalR/SignalR/issues/3548#issuecomment-296326048

Josh M.
  • 23,573
  • 23
  • 96
  • 160
0

For me it started failing after I updated .NET Framework from 4.5.2 to 4.7 All I did to fix it was update the Nuget Package WindowsAzure.ServiceBus to 5.2.0

Bruno Henn
  • 51
  • 3