Question

I am trying to use NServiceBus (version 4.6.0.0) with an ASP.NET MVC application hosted in a Windows Azure Website and Azure Storage for persistence but am having problems with the TimeoutManager.

Before trying to use Azure I got my app working with NServiceBus using the default MSMQ and RavenDB settings and then changed over to using Azure Storage. With that setup however I am getting multiple NullReferenceException errors right after startup in NServiceBus.Azure.TimoutManagerPersister.TryGetLastSuccessfulRead().

I have tried running this local using the Storage Emulator and with everything deployed to Azure and have the same error on both.

Here is how I have NServiceBus setup in my app:

Global.asax.cs

public class MvcApplication : System.Web.HttpApplication
{
    public static IBus Bus { get; private set; }

    protected void Application_Start()
    {
        ...

        Configure.ScaleOut(s => s.UseSingleBrokerQueue());
        Feature.Enable<Sagas>();

        IStartableBus startableBus = Configure.With()
            .DefaultBuilder()
            .DefineEndpointName("MyApp.Web")
            .AzureConfigurationSource()
            .UseTransport<AzureStorageQueue>()
            .AzureMessageQueue()
            .AzureSubscriptionStorage()
            .UseAzureTimeoutPersister()
            .AzureSagaPersister()
            .PurgeOnStartup(false)
            .UnicastBus()
            .LoadMessageHandlers()
            .RunHandlersUnderIncomingPrincipal(false)
            .Log4Net(new DebugAppender { Threshold = Level.Warn })
            .RijndaelEncryptionService()
            .CreateBus();

        Configure.Instance.ForInstallationOn<Windows>().Install();
        Bus = startableBus.Start();
    }
}

Web.config

<configSections>
    <section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
    <section name="AuditConfig" type="NServiceBus.Config.AuditConfig, NServiceBus.Core" />
    <section name="AzureProfileConfig" type="NServiceBus.Config.AzureProfileConfig, NServiceBus.Hosting.Azure" />
    <section name="AzureSubscriptionStorageConfig" type="NServiceBus.Config.AzureSubscriptionStorageConfig, NServiceBus.Azure" />
    <section name="AzureSagaPersisterConfig" type="NServiceBus.Config.AzureSagaPersisterConfig, NserviceBus.Azure" />
    <section name="AzureTimeoutPersisterConfig" type="NServiceBus.Config.AzureTimeoutPersisterConfig, NserviceBus.Azure" />
  </configSections>

  <connectionStrings>
    <add name="NServiceBus/Transport" connectionString="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey" />
  </connectionStrings>

<AzureSagaPersisterConfig ConnectionString="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey" CreateSchema="true" />
  <AzureTimeoutPersisterConfig ConnectionString="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey" TimeoutManagerDataTableName="TimeoutManagerData" TimeoutDataTableName="TimeoutData" />
  <AzureSubscriptionStorageConfig ConnectionString="DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey" />

And here is the exception I am getting:

System.NullReferenceException was unhandled by user code
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=Microsoft.Data.Services.Client
  StackTrace:
       at System.Data.Services.Client.UriWriter.VisitResourceSetExpression(ResourceSetExpression rse)
       at System.Data.Services.Client.DataServiceALinqExpressionVisitor.Visit(Expression exp)
       at System.Data.Services.Client.UriWriter.Translate(DataServiceContext context, Boolean addTrailingParens, Expression e, Uri& uri, Version& version)
       at System.Data.Services.Client.DataServiceQueryProvider.Translate(Expression e)
       at System.Data.Services.Client.DataServiceQuery`1.Translate()
       at System.Data.Services.Client.DataServiceQuery`1.Execute()
       at System.Data.Services.Client.DataServiceQuery`1.GetEnumerator()
       at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
       at NServiceBus.Azure.SafeLinqExtensions.SafeFirstOrDefault[TSource](IEnumerable`1 source) in y:\BuildAgent\work\ba77a0c29cee2af1\src\NServiceBus.Azure\SafeLinqExtensions.cs:line 13
       at NServiceBus.Azure.TimeoutPersister.TryGetLastSuccessfulRead(ServiceContext context, TimeoutManagerDataEntity& lastSuccessfulReadEntity) in
       y:\BuildAgent\work\ba77a0c29cee2af1\src\NServiceBus.Azure\Timeout\TimeoutLogic\TimeoutPersister.cs:line 338
       at NServiceBus.Azure.TimeoutPersister.GetNextChunk(DateTime startSlice, DateTime& nextTimeToRunQuery) in y:\BuildAgent\work\ba77a0c29cee2af1\src\NServiceBus.Azure\Timeout\TimeoutLogic\TimeoutPersister.cs:line 27
       at NServiceBus.Timeout.Hosting.Windows.TimeoutPersisterReceiver.Poll(Object obj) in y:\BuildAgent\work\31f8c64a6e8a2d7c\src\NServiceBus.Core\Timeout\Hosting\Windows\TimeoutPersisterReceiver.cs:line 80
       at System.Threading.Tasks.Task.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()

Even with the error messages are getting added to the Azure queue and are being processed but only for a couple of minutes than the TimeoutManager stops processing and messages are not dequeued.

Was it helpful?

Solution

Sounds like something is wrong in the storage sdk that you are using, which version are you on?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top