web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Creating Azure file share using X++

(3) ShareShare
ReportReport
Posted on by 98
Good afternoon,
 
I am having an issue creating an Azure file share which has started happening after the upgrade to PU67. Interestingly, this does work as expected on a Dev environment, but not on the tier 2 sandbox.
 
Code as follows:
            permission = new InteropPermission(InteropKind::ClrInterop);
            permission.assert();

            //Setting connection
            storageCredentials = new Microsoft.Azure.Storage.Auth.StorageCredentials(vendParameters.bbsAzureStorageAcntName, vendParameters.bbsAzureStorageAcntPw);
            storageAccount = new Microsoft.Azure.Storage.CloudStorageAccount(storageCredentials, true);
            fileClient = storageAccount.CreateCloudFileClient();
            fileShare = fileClient.GetShareReference(_agentShareName);

            if (!fileShare.Exists(null, null))
            {
                warning('  Fileshare does not exist, creating...');
                fileShare.CreateIfNotExists(null, null);
                Info('  Fileshare create attempted. Checking...');
                Counter i = 0;
                while (!fileShare.Exists(null, null) && i < 60)
                {
                    sleep(1000);
                    i++;
                }
                if (fileShare.Exists(null, null))
                {
                    Info(strfmt('File share created after %1s',i));
                }
                else {
                    error('Fileshare could not be created');
                }
            }
 
This code is inside a try...catch block and grabs an exception thrown by the line fileshare.CreateIfNotExists(null, null). I get the "Fileshare does not exist, creating..." warning, and then an exception caught by the catch block:
Exception has been thrown by the target of an invocation
The specified resource does not exist.
Am I fundamentally misunderstanding the use of the CreateIfNotExists() method here, or is there a gotcha/additional check that I'm missing?
 
Categories:
I have the same question (0)
  • Verified answer
    Vahid Ghafarpour Profile Picture
    12,166 Super User 2025 Season 2 on at
    The code uses the Microsoft.Azure.Storage namespace, which is part of the older Azure Storage SDK.
    Consider updating to the newer Azure.Storage.Files.Shares SDK, which provides better support and more detailed error handling.
    If updating is not an option, ensure that the API version used by the sandbox environment is compatible with the CreateIfNotExists() method.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans