I have a simple web callback API that I've built in C# using ASP.NET Core 6. The application works perfectly fine locally and runs on an IIS server with no issues. I updated it to test it as an AWS Serverless Application using ASP.NET Core framework in Amazon Lambda, and it immediately fails with the following message:
The type initializer for 'PureCloudPlatform.Client.V2.Client.Configuration' threw an exception.
WebCallbackAWS
System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
at System.IO.Path.Combine(String path1, String path2, String path3)
at PureCloudPlatform.Client.V2.Client.Configuration..ctor(ApiClient apiClient, Dictionary2 defaultHeader, String username, String password, String accessToken, Dictionary2 apiKey, Dictionary`2 apiKeyPrefix, String tempFolderPath, String dateTimeFormat, Int32 timeout, Boolean shouldRefreshAccessToken, Int32 refreshTokenWaitTime, String userAgent, String configFilePath, Boolean autoReloadConfig)
at PureCloudPlatform.Client.V2.Client.Configuration..cctor() at WebCallbackAWS.GCCheckSchedules.GetScheduleGroup(String scheduleGroupName)
This failure occurs as soon as I attempt to set the region for the application and prior to attempting authentication. Further testing gives the same type of error setting the retry config.
Has anyone else run into a similar issue?
I'm using PureCloudPlatform v 162.0.0.
Any assistance/recommendations would be greatly appreciated.
I would classify this as a known problem. The SDK looks for
Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
And then tries to combine that to find a config file, but on a serverless app there is no such path and Path.Combine isn't handled for nulls so it crashes.
Away to avoid that is don't use Configuration.Default.
Explicitly create your own Configuration object and explicitly pass it a value for configFilePath so it won't crash trying to make up it's own;
Configuration configuration = new Configuration(configFilePath: ".genesysclouddotnetconfig");
configuration.ApiClient.setBasePath( region );
Thank-you for the recommendation. I tried to follow what you provided and I'm still getting the exact same error when running in AWS.
I can verify that the change to the file path is taking place on my local machine, however as soon as I try to run this in AWS it fails trying to set the config file path.
Are there any other options I might be able to try in order to get around this limitation?
I stepped through it and it looks like they're forcing Default to be created regardless as soon as the object exists, so there's no escaping it.
Your plan B would be just to set those variables with "" yourself before beginning your Client Setup;