Question

I’m getting the following exception when trying to upload a file with the following code:

            string encodedUrl = "videos/Sample.mp4"
            CloudBlockBlob encodedVideoBlob = blobClient.GetBlockBlobReference(encodedUrl);
            Log(string.Format("Got blob reference for {0}", encodedUrl), EventLogEntryType.Information);
            encodedVideoBlob.Properties.ContentType = contentType;
            encodedVideoBlob.Metadata[BlobProperty.Description] = description;
            encodedVideoBlob.UploadFile(localEncodedBlobPath);

I see the "Got blob reference" message, so I assume the reference resolves correctly.

Void Run() C:\Inter\Projects\PoC\WorkerRole\WorkerRole.cs (40)
System.ArgumentNullException: Value cannot be null.
Parameter name: value
   at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()
   at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait()
   at Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(Stream source, BlobRequestOptions options)
   at Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFile(String fileName, BlobRequestOptions options)
   at EncoderWorkerRole.WorkerRole.ProcessJobOutput(IJob job, String videoBlobToEncodeUrl) in C:\Inter\Projects\PoC\WorkerRole\WorkerRole.cs:line 144
   at EncoderWorkerRole.WorkerRole.Run() in C:\Inter\Projects\PoC\WorkerRole\WorkerRole.cs:line 40

Interestingly, I'm running that same snippet from an on-premises server i.e., outside of Azure and it works correctly.

Ideas welcome, thanks!

Was it helpful?

Solution

Found the culprit!

Basically, problem was in this line

encodedVideoBlob.Metadata[BlobProperty.Description] = description;

There's a check well down that makes sure no null or empty metadata is being set. Found it by disassembling from Reflector and searching for ArgumentNullException ocurrences.

Could be great to catch and re-throw a more meaningful exception up in the stack :-)

Here are the interesting methods:

internal static void AddMetadata(HttpWebRequest request, NameValueCollection metadata)
{
    if (metadata != null)
    {
        foreach (string str in metadata.AllKeys)
        {
            AddMetadata(request, str, metadata[str]);
        }
    }
}

internal static void AddMetadata(HttpWebRequest request, string name, string value)
{
    CommonUtils.AssertNotNullOrEmpty("value", value);
    request.Headers.Add("x-ms-meta-" + name, value);
}


internal static void AssertNotNullOrEmpty(string paramName, string value)
{
    AssertNotNull(paramName, value);
    if (string.IsNullOrEmpty(value))
    {
        throw new ArgumentException(Microsoft.WindowsAzure.SR.ArgumentEmptyError, paramName);
    }
}

internal static void AssertNotNull(string paramName, object value)
{
    if (value == null)
    {
        throw new ArgumentNullException(paramName);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top