Repository: microsoft/kiota (csharp)

Issue:
If --backing-store is used for Microsoft.Graph warning CS8603 is generated
Generated code should be warning free imho.

Sample date:

```
.\Models\AccessPackageAnswerChoice.cs(27,26,27,90): warning CS8603: Possible null reference return.
.\Models\DelegatedAdminAccessContainer.cs(32,26,32,90): warning CS8603: Possible null reference return.
.\Models\DeviceActionResult.cs(35,26,35,90): warning CS8603: Possible null reference return.
.\Models\Fido2KeyRestrictions.cs(27,26,27,90): warning CS8603: Possible null reference return.
.\Models\OnPremisesDirectorySynchronizationConfiguration.cs(27,26,27,90): warning CS8603: Possible null reference return.
.\Models\OptionalClaims.cs(27,26,27,90): warning CS8603: Possible null reference return.
.\Models\Process.cs(27,26,27,90): warning CS8603: Possible null reference return.
.\Models\RecommendedAction.cs(27,26,27,90): warning CS8603: Possible null reference return.
.\Models\Security\LoggedOnUser.cs(27,26,27,90): warning CS8603: Possible null reference return.
.\Models\Security\UserAccount.cs(27,26,27,90): warning CS8603: Possible null reference return.
.\Models\SynchronizationTaskExecution.cs(27,26,27,90): warning CS8603: Possible null reference return.
.\Models\UserSecurityState.cs(41,26,41,90): warning CS8603: Possible null reference return.
```

Pull request:
Fixes #4506

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 870737341b..bbc3658e93 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - Changed URI template generation to reuse templates when required templates are absent across operations.
 - Updated reserved name providers for Java and Php so that "object" can be escaped. 
+- Do not generate CS8603 warnings when enabling backing store in CSharp generation. 
 
 ## [1.13.0] - 2024-04-04
 
diff --git a/src/Kiota.Builder/Writers/CSharp/CodePropertyWriter.cs b/src/Kiota.Builder/Writers/CSharp/CodePropertyWriter.cs
index 3f00038af6..4b0baaf35c 100644
--- a/src/Kiota.Builder/Writers/CSharp/CodePropertyWriter.cs
+++ b/src/Kiota.Builder/Writers/CSharp/CodePropertyWriter.cs
@@ -50,10 +50,12 @@ private void WritePropertyInternal(CodeProperty codeElement, LanguageWriter writ
             case CodePropertyKind.AdditionalData when backingStoreProperty != null:
             case CodePropertyKind.Custom when backingStoreProperty != null:
                 var backingStoreKey = codeElement.WireName;
+                var nullableOp = !codeElement.IsOfKind(CodePropertyKind.AdditionalData) ? "?" : string.Empty;
+                var nullableEx = codeElement.IsOfKind(CodePropertyKind.AdditionalData) ? " ?? throw new InvalidOperationException(\"AdditionalData can not be null\")" : string.Empty;
                 writer.WriteLine($"{conventions.GetAccessModifier(codeElement.Access)} {propertyType} {codeElement.Name.ToFirstCharacterUpperCase()} {{");
                 writer.IncreaseIndent();
-                writer.WriteLine($"get {{ return {backingStoreProperty.Name.ToFirstCharacterUpperCase()}?.Get<{propertyType}>(\"{backingStoreKey}\"); }}");
-                writer.WriteLine($"set {{ {backingStoreProperty.Name.ToFirstCharacterUpperCase()}?.Set(\"{backingStoreKey}\", value); }}");
+                writer.WriteLine($"get {{ return {backingStoreProperty.Name.ToFirstCharacterUpperCase()}{nullableOp}.Get<{propertyType}>(\"{backingStoreKey}\"){nullableEx}; }}");
+                writer.WriteLine($"set {{ {backingStoreProperty.Name.ToFirstCharacterUpperCase()}{nullableOp}.Set(\"{backingStoreKey}\", value); }}");
                 writer.DecreaseIndent();
                 writer.WriteLine("}");
                 break;


Test patch:
diff --git a/tests/Kiota.Builder.Tests/Writers/CSharp/CodePropertyWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/CSharp/CodePropertyWriterTests.cs
index 27516fbfd2..a1d78fd859 100644
--- a/tests/Kiota.Builder.Tests/Writers/CSharp/CodePropertyWriterTests.cs
+++ b/tests/Kiota.Builder.Tests/Writers/CSharp/CodePropertyWriterTests.cs
@@ -113,8 +113,8 @@ public void MapsAdditionalDataPropertiesToBackingStore()
         property.Kind = CodePropertyKind.AdditionalData;
         writer.Write(property);
         var result = tw.ToString();
-        Assert.Contains("get { return BackingStore?.Get<SomeCustomClass>(\"propertyName\"); }", result);
-        Assert.Contains("set { BackingStore?.Set(\"propertyName\", value);", result);
+        Assert.Contains("get { return BackingStore.Get<SomeCustomClass>(\"propertyName\") ?? throw new InvalidOperationException(\"AdditionalData can not be null\"); }", result);
+        Assert.Contains("set { BackingStore.Set(\"propertyName\", value);", result);
     }
     [Fact]
     public void WritesSerializationAttribute()