visual-studioazure-functionsazurite

Customized storage account(s) for Azurite on local windows with VS not working


I have a similar issue as here, but this is running Azurite on windows with VS against an Azure Function.

I am trying to follow this documentation

Azurite is being initiated by VS through this setting in local.settings.json in the Azure Functions project:

"AzureWebJobsStorage": "UseDevelopmentStorage=true"

I have set the environment variables (also tried without quotation marks):

cmdscreenshot

My connection string is like this:

"DefaultEndpointsProtocol=http;AccountName=imageaccount;AccountKey=SU1BR0VfQkxPQl9TVE9SQUdFX1VSTA==;BlobEndpoint=http://127.0.0.1:10000/imageaccount;"

My BlobContainerClient seems set up to go: enter image description here

but calling

 await containerClient.CreateIfNotExistsAsync();

throws an exception telling me it is an "Invalid storage account"?

Further info:

Disabling Azurite startup in VS and running azurite from the console produces another exception with this message:

"The API version 2022-11-02 is not supported by Azurite. Please upgrade Azurite to latest version and retry. If you are using Azurite in Visual Studio, please check you have installed latest Visual Studio patch. Azurite command line parameter "--skipApiVersionCheck" or Visual Studio Code configuration "Skip Api Version Check" can skip this error. "

Running from console with the proposed --skipApiVersionCheck I am back to the original exception.

Setting up without the AZURITE_ACCOUNTS environment setting, and with "UseDevelopmentStorage=true" as connection string works

Any clues? Thx..


Solution

  • A workaround was found in this github issue

    Currently there is flaws in the documentation and it lacks important details, so to make this work in the questions context, here is the way to go:

    Here is a .bat script for convenience (run as administrator):

    cd C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Azure Storage Emulator
    set AZURITE_ACCOUNTS=set AZURITE_ACCOUNTS=account1:key1;account2:key2
    azurite --skipApiVersionCheck
    

    An alternative more "permanent" solution (keep the "AzureWebJobsStorage": "UseDevelopmentStorage=true" to start Azurite from VS) is adding the environment variable manually to the windows system variables e.g.

    (for what ever reason, the setting must be set in the first startup project when using multiple startup projects in a solution)

    enter image description here