microsoft / PowerPlatform-DataverseServiceClient

Code Replica for Microsoft.PowerPlatform.Dataverse.Client and supporting nuget packages.
MIT License
277 stars 50 forks source link

Total crash when ConfigurationManager can't be initialized #326

Closed matkov closed 1 year ago

matkov commented 1 year ago

Total crash when ConfigurationManager can't be initialized.

namespace Microsoft.PowerPlatform.Dataverse.Client.Utils

class AppSettingsHelper

This method public static T GetAppSetting(string key, T defaultValue, DataverseTraceLogger logSink = null) has catch { ... } section

But method public static TimeSpan GetAppSettingTimeSpan(string key , TimeSpanFromKey format , TimeSpan defaultValue, DataverseTraceLogger logSink = null) doesn't have catch { ... } section and when ConfigurationManager raise an Exception then Microsoft.PowerPlatform.Dataverse.Client.ServiceClient will crash when trying to initialize this property:

public static TimeSpan InMemoryLogCollectionTimeOutMinutes { get; set; } = Utils.AppSettingsHelper.GetAppSettingTimeSpan("InMemoryLogCollectionTimeOutMinutes", Utils.AppSettingsHelper.TimeSpanFromKey.Minutes, TimeSpan.FromMinutes(5));

To resolve this issue you should add catch { ... } section to the GetAppSettingTimeSpan method.

MattB-msft commented 1 year ago

@matkov - Thanks for your contribution!, We will accept this PR into our primary repository and close this when completed.