microsoftgraph / msgraph-beta-sdk-dotnet

The Microsoft Graph Client Beta Library for .NET supports the Microsoft Graph /beta endpoint. (preview)
Other
96 stars 32 forks source link

[Client bug]: System.NullReferenceException when trying to remove an Extension Property from AD object #329

Closed thiagodpaz closed 3 years ago

thiagodpaz commented 3 years ago

Describe the bug After upgrading from 0.35.0-preview to 4.6.0-preview, trying to remove an Extension Property from a Group (by setting it to null) fails with System.NullReferenceException.

To Reproduce Steps to reproduce the behavior:

The GraphBeta alias below is to allow usage of both Beta and 1.0 Graph endpoints by using the regular and the preview SDKs in the project.

graphServiceClient is a valid GraphServiceClient object appId is the registered AAD application ID directoryObjectId is the AD Group GUID

var internalExtensionName = $"extension_{appId.Replace("-", string.Empty)}_{entensionName}";
var objectoToUpdate = new GraphBeta.Group { Id = directoryObjectId, AdditionalData = new Dictionary<string, object>() };
objectoToUpdate.AdditionalData.Add(internalExtensionName, null);
await graphServiceClient.Groups[directoryObjectId].Request().UpdateAsync(objectoToUpdate);

Expected behavior After setting the extension property to null it should be removed from the Group object.

Please note: Adding an extension property still works in 4.6.0-preview SDK. Adding and removing an extension property works fine on 0.35.0-preview SDK.

Client version Microsoft.Graph.Beta 4.6.0-preview

Desktop (please complete the following information):

Additional context

 ShouldSetAndRemoveExtensionProperty Source: GraphTests.cs line 326 Duration: 2.7 min

Message: Test method Shared.Graph.Test.GraphTests.ShouldSetAndRemoveExtensionProperty threw exception: System.NullReferenceException: Object reference not set to an instance of an object.

Stack Trace: Object.GetType() DerivedTypeConverter1.Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) JsonConverter1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) JsonConverter1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) JsonConverter1.WriteCoreAsObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options, WriteStack& state) JsonSerializer.WriteCore[TValue](JsonConverter jsonConverter, Utf8JsonWriter writer, TValue& value, JsonSerializerOptions options, WriteStack& state) JsonSerializer.WriteCore[TValue](Utf8JsonWriter writer, TValue& value, Type inputType, JsonSerializerOptions options) JsonSerializer.Serialize[TValue](TValue& value, Type inputType, JsonSerializerOptions options) JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options) Serializer.SerializeObject(Object serializeableObject) BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption) BaseRequest.SendAsync[T](Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption) GroupRequest.UpdateAsync(Group groupToUpdate, CancellationToken cancellationToken) GraphClientQueryHelperExtensions.RemoveExtensionProperty(GraphServiceClient graphServiceClient, DirectoryObjectType directoryObjectType, String directoryObjectId, String appId, String extensionName) line 160 GraphTests.ShouldSetAndRemoveExtensionProperty() line 370 ThreadOperations.ExecuteWithAbortSafety(Action action)

Standard Output: Debug Trace: GetIConfigurationRoot() Loading: Settings\Settings.json Loading: Settings\Settings.local.json

AB#10448

thiagodpaz commented 3 years ago

Thanks for the fix. I can confirm Microsoft.Graph.Beta 4.7.0-preview fixed the issue.