smartsheet-platform/smartsheet-csharp-sdk

.NET Core unhandled exception

okpedro opened this issue · 1 comments

I am using .NET Core 2.2. When GetOSFriendlyName() gets called, the following exception is being thrown:

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'System.Management.ManagementPath' threw an exception.
  Source=System.Management
  StackTrace:
   at System.Management.ManagementScope._Clone(ManagementScope scope, IdentifierChangedEventHandler handler)
   at System.Management.ManagementObjectSearcher..ctor(ManagementScope scope, ObjectQuery query, EnumerationOptions options)
   at Smartsheet.Api.Internal.Utility.Utility.GetOSFriendlyName() in C:\Users\Pedro\Source\repos\SmartSheetImporter\SmartSheetImporter\Smartsheet\Api\Internal\Util\Util.cs:line 38
   at Smartsheet.Api.Internal.SmartsheetImpl.GenerateUserAgent(String userAgent) in C:\Users\Pedro\Source\repos\SmartSheetImporter\SmartSheetImporter\Smartsheet\Api\Internal\SmartsheetImpl.cs:line 610
   at Smartsheet.Api.Internal.SmartsheetImpl.set_UserAgent(String value) in C:\Users\Pedro\Source\repos\SmartSheetImporter\SmartSheetImporter\Smartsheet\Api\Internal\SmartsheetImpl.cs:line 347
   at Smartsheet.Api.Internal.SmartsheetImpl..ctor(String baseURI, String accessToken, HttpClient httpClient, JsonSerializer jsonSerializer) in C:\Users\Pedro\Source\repos\SmartSheetImporter\SmartSheetImporter\Smartsheet\Api\Internal\SmartsheetImpl.cs:line 269
   at SmartSheetImporter.AppStart.BuildSmartsheetClient() in C:\Users\Pedro\Source\repos\SmartSheetImporter\SmartSheetImporter\AppStart.cs:line 110
   at SmartSheetImporter.AppStart.<>c.<ConfigureServices>b__12_1(IServiceProvider smartSheet) in C:\Users\Pedro\Source\repos\SmartSheetImporter\SmartSheetImporter\AppStart.cs:line 47
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at SmartSheetImporter.AppStart.RefreshData() in C:\Users\Pedro\Source\repos\SmartSheetImporter\SmartSheetImporter\AppStart.cs:line 76
   at SmartSheetImporter.AppStart.Main(String[] args) in C:\Users\Pedro\Source\repos\SmartSheetImporter\SmartSheetImporter\AppStart.cs:line 70

Inner Exception 1:
TypeInitializationException: The type initializer for 'System.Management.WmiNetUtilsHelper' threw an exception.

Inner Exception 2:
ArgumentNullException: Value cannot be null.
Parameter name: ptr

it seems there is some logic to attempt to figure out if .Net Core is being used in the following catch:

catch (System.NotImplementedException)
            {
                return ".Net Core-" + System.Environment.OSVersion.VersionString;
            }

I replaced the System.NotImplementedException with a generic exception to make it work.

closing this as a duplicate of #69