Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Azure Blob storage failing to download in Maui app (debugging on Windows MAchine)

$
0
0

I'm new to MAUI, but I've been trying to port an existing project I made into a Blazor hybrid app. I'm having an issue downloading a file (while debugging) from an azure blob store. (To clarify, might also not work when not debugging, but I haven't tried that yet)

What I have working:I can list the blobs with the following code:

var containerClient = new BlobContainerClient(new Uri(containerSasUrl));var blobs = containerClient.GetBlobs().ToList();

So I can see the blob exists. Then I try to grab a download using the following code:

var blobName = blob.Name; //blob is technically a BlobItem from the method above.var containerClient = new BlobContainerClient(new Uri(containerSasUrl));var blobClient = containerClient.GetBlobClient(blobName);var newPath = Path.Combine(FileSystem.AppDataDirectory, blobName);var r = await blobClient.DownloadToAsync(newPath);

I get an exception in the await. I have no idea what that exception is, because the next thing I see while debugging is the Razor component that called this method, and the first use of the Model, which is null (the exception is in BuildRenderTree). I've tried wrapping in a try/catch, but the catch is never hit, even when I'm stepping through the code (I suspect it's some sort of async issue with what the context is?)

The method that calls the download sequence is being called from within protected override async Task OnInitializedAsync(), which is just inside a @code{} block in my razor file.

I've tried setting all the exceptions to be hit, but it doesn't give me a different result.

Also, it does seem to start the download, or at least it's getting as far as creating the file in the Data folder (it's obviously at 0bytes).

I would like help, if possible, with why this download is failing, but also how to actually handle this with a try/catch or other mechanism, so that it doesn't cause the rest of the app to fail (since it's not a necessary download).

Thank you for any help.Azure.Storage.Blobs -> 12.25.0

WebView.Maui -> 9.0.51

UPDATE: I realize that BlobClient exposes a DownloadTo method (which is non-async based on the github example), so I know the download works. It's not a big file and I can't progress until it finishes downloading, so async isn't required, but I still want to know why a)the async version is crashing

b)why wrapping the await in a try/catch doesn't catch the error like in other c# code.

Also, none of the methods are async void.


Viewing all articles
Browse latest Browse all 4839

Trending Articles