0

I'm getting an exception when trying to update a message on a cloud queue.

The exception is:

System.ArgumentNullException was unhandled
  Message=Value cannot be null.
Parameter name: messageId
  Source=Microsoft.WindowsAzure.StorageClient
  ParamName=messageId
  StackTrace:
       at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()
       at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait()
       at Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImplWithRetry(Func`1 impl, RetryPolicy policy)
       at Microsoft.WindowsAzure.StorageClient.CloudQueue.UpdateMessage(CloudQueueMessage message, TimeSpan visibilityTimeout, MessageUpdateFields updateFields)
       at WorkerRole.WorkerRole.DoTask(Task task) in C:\Users\ALICE\Desktop\Diplloma\AG - Copy\AzureGrid\WorkerRole\WorkerRole.cs:line 133
       at WorkerRole.WorkerRole.Run() in C:\Users\ALICE\Desktop\Diplloma\AG - Copy\AzureGrid\WorkerRole\WorkerRole.cs:line 51
       at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRoleInternal()
       at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRole()
       at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.<StartRole>b__1()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

My code is:

private void DoTask(Task task)
{
    CloudQueueMessage resultsMessage;

    // Queue a status message to indicate this worker is starting the task.
    task.TaskStatus = Task.Status.Running;
    task.Worker = System.Net.Dns.GetHostName();
    resultsMessage = task.Message;
    ResultsQueue.UpdateMessage(resultsMessage, TimeSpan.FromSeconds(QueueTimeout), MessageUpdateFields.Content | MessageUpdateFields.Visibility);


    Trace.WriteLine("Executing task " + task.TaskId.ToString() + " for job " + task.JobId + ", project " + task.ProjectName,"Information");

    using (GridWorker gridWorker = new AppWorker())
    {
        gridWorker.Execute(task);
    }

    // Queue results.
    task.TaskStatus = Task.Status.Complete;
    resultsMessage = task.Message;
    ResultsQueue.UpdateMessage(resultsMessage, TimeSpan.FromSeconds(QueueTimeout), MessageUpdateFields.Content | MessageUpdateFields.Visibility);
}

Here is how the task object is created

public override void Run()
{
    CloudQueueMessage taskMessage;
    Task task;

    // This is a sample worker implementation. Replace with your logic.
    Trace.WriteLine("Initializing", "Information");

    LoadConfigurationSettings();
    OpenQueues();

    Trace.WriteLine("Initializing", "Ready for work");

    // Work loop. Read a task from the queue. If there is a task, execute it and pass work output to the results queue. Loop.

    while (true)
    {
        taskMessage = TaskQueue.GetMessage(TimeSpan.FromSeconds(QueueTimeout));
        //taskMessage = TaskQueue.PeekMessage();

        if (taskMessage != null)
        {
            task = new Task(taskMessage);
            DoTask(task);
            TaskQueue.DeleteMessage(taskMessage);
        }
        else
            Thread.Sleep(SleepInterval * 1000);
    }
}

This is my first application, and I don't understand what to do.

abatishchev
  • 92,232
  • 78
  • 284
  • 421
MIlena
  • 257
  • 1
  • 4
  • 13

1 Answers1

2

Where did task.Message come from? Was it previously read from the queue? (It seems to be missing a message ID.)

user94559
  • 54,841
  • 6
  • 85
  • 93
  • Thank you for your answer. task.Message is a property which contains some xml data converted in string. – MIlena Sep 03 '12 at 06:52
  • Well, `task.Message` has to be an object of type `CloudQueueMessage`, right? Where did that `CloudQueueMessage` come from? Did you retrieve it from the queue? – user94559 Sep 03 '12 at 10:41
  • Oh yes sorry. Message is type of CouldQueueMessage, but it's purpose is to store some data, and this data is some xml data converted in string. – MIlena Sep 03 '12 at 14:51
  • I updated the code. Now you can see and help me how to deal with that. I don't understand, should I explicitly set the message id? How to do that? – MIlena Sep 03 '12 at 15:24
  • 2
    It looks like you're trying to update a message in the wrong queue. You're reading from `TaskQueue` but then trying to update the message in `ResultsQueue`, which doesn't contain the message you're updating. – user94559 Sep 03 '12 at 16:10
  • Ohhh yeeees thats the problem.. THANK YOUUUU – MIlena Sep 03 '12 at 22:26