Skip to content

Commit

Permalink
SendPrimitiveAsync throws InvalidOperationException for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinM85 committed Jul 11, 2024
1 parent 7c04186 commit 006bdfc
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.9.9] - 2024-07-11

- Fix enum deserialization for SendPrimitiveAsync and

## [1.9.8] - 2024-07-08

- Migrated source of various libraries to mono repository at <https://github.com/microsoft/kiota-dotnet>.
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- Common default project properties for ALL projects-->
<PropertyGroup>
<VersionPrefix>1.9.8</VersionPrefix>
<VersionPrefix>1.9.9</VersionPrefix>
<VersionSuffix></VersionSuffix>
<!-- This is overidden in test projects by setting to true-->
<IsTestProject>false</IsTestProject>
Expand Down
8 changes: 0 additions & 8 deletions src/abstractions/IRequestAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,15 @@ public interface IRequestAdapter
/// <param name="errorMapping">The error factories mapping to use in case of a failed request.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use for cancelling the requests.</param>
/// <returns>The deserialized primitive response model.</returns>
#if NET5_0_OR_GREATER
Task<ModelType?> SendPrimitiveAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] ModelType>(RequestInformation requestInfo, Dictionary<string, ParsableFactory<IParsable>>? errorMapping = default, CancellationToken cancellationToken = default);
#else
Task<ModelType?> SendPrimitiveAsync<ModelType>(RequestInformation requestInfo, Dictionary<string, ParsableFactory<IParsable>>? errorMapping = default, CancellationToken cancellationToken = default);
#endif
/// <summary>
/// Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model collection.
/// </summary>
/// <param name="requestInfo">The RequestInformation object to use for the HTTP request.</param>
/// <param name="errorMapping">The error factories mapping to use in case of a failed request.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use for cancelling the requests.</param>
/// <returns>The deserialized primitive response model collection.</returns>
#if NET5_0_OR_GREATER
Task<IEnumerable<ModelType>?> SendPrimitiveCollectionAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] ModelType>(RequestInformation requestInfo, Dictionary<string, ParsableFactory<IParsable>>? errorMapping = default, CancellationToken cancellationToken = default);
#else
Task<IEnumerable<ModelType>?> SendPrimitiveCollectionAsync<ModelType>(RequestInformation requestInfo, Dictionary<string, ParsableFactory<IParsable>>? errorMapping = default, CancellationToken cancellationToken = default);
#endif
/// <summary>
/// Executes the HTTP request specified by the given RequestInformation with no return content.
/// </summary>
Expand Down
8 changes: 0 additions & 8 deletions src/http/httpClient/HttpClientRequestAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,7 @@ public string? BaseUrl
/// <param name="errorMapping">The error factories mapping to use in case of a failed request.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use for cancelling the request.</param>
/// <returns>The deserialized primitive response model collection.</returns>
#if NET5_0_OR_GREATER
public async Task<IEnumerable<ModelType>?> SendPrimitiveCollectionAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] ModelType>(RequestInformation requestInfo, Dictionary<string, ParsableFactory<IParsable>>? errorMapping = default, CancellationToken cancellationToken = default)
#else
public async Task<IEnumerable<ModelType>?> SendPrimitiveCollectionAsync<ModelType>(RequestInformation requestInfo, Dictionary<string, ParsableFactory<IParsable>>? errorMapping = default, CancellationToken cancellationToken = default)
#endif
{
using var span = startTracingSpan(requestInfo, nameof(SendPrimitiveCollectionAsync));
var response = await GetHttpResponseMessage(requestInfo, cancellationToken, span).ConfigureAwait(false);
Expand Down Expand Up @@ -209,11 +205,7 @@ public string? BaseUrl
/// <param name="errorMapping">The error factories mapping to use in case of a failed request.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use for cancelling the request.</param>
/// <returns>The deserialized primitive response model.</returns>
#if NET5_0_OR_GREATER
public async Task<ModelType?> SendPrimitiveAsync<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields)] ModelType>(RequestInformation requestInfo, Dictionary<string, ParsableFactory<IParsable>>? errorMapping = default, CancellationToken cancellationToken = default)
#else
public async Task<ModelType?> SendPrimitiveAsync<ModelType>(RequestInformation requestInfo, Dictionary<string, ParsableFactory<IParsable>>? errorMapping = default, CancellationToken cancellationToken = default)
#endif
{
using var span = startTracingSpan(requestInfo, nameof(SendPrimitiveAsync));
var modelType = typeof(ModelType);
Expand Down
8 changes: 0 additions & 8 deletions tests/http/httpClient/RequestAdapterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ public async Task ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode)
}
}
[Fact]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Trimming", "IL2066:The generic parameter of type or method has a DynamicallyAccessedMembersAttribute, but the value used for it can not be statically analyzed.", Justification = "<Pending>")]
public async Task SendPrimitiveHandleEnumIfValueIsString()
{
var mockHandler = new Mock<HttpMessageHandler>();
Expand Down Expand Up @@ -570,7 +569,6 @@ public async Task SendPrimitiveHandleEnumIfValueIsString()
}

[Fact]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Trimming", "IL2066:The generic parameter of type or method has a DynamicallyAccessedMembersAttribute, but the value used for it can not be statically analyzed.", Justification = "<Pending>")]
public async Task SendPrimitiveHandleEnumIfValueIsInteger()
{
var mockHandler = new Mock<HttpMessageHandler>();
Expand Down Expand Up @@ -603,7 +601,6 @@ public async Task SendPrimitiveHandleEnumIfValueIsInteger()
}

[Fact]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Trimming", "IL2066:The generic parameter of type or method has a DynamicallyAccessedMembersAttribute, but the value used for it can not be statically analyzed.", Justification = "<Pending>")]
public async Task SendPrimitiveHandleEnumIfValueIsFromEnumMember()
{
var mockHandler = new Mock<HttpMessageHandler>();
Expand Down Expand Up @@ -636,7 +633,6 @@ public async Task SendPrimitiveHandleEnumIfValueIsFromEnumMember()
}

[Fact]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Trimming", "IL2066:The generic parameter of type or method has a DynamicallyAccessedMembersAttribute, but the value used for it can not be statically analyzed.", Justification = "<Pending>")]
public async Task SendPrimitiveReturnsNullIfValueCannotBeParsedToEnum()
{
var mockHandler = new Mock<HttpMessageHandler>();
Expand Down Expand Up @@ -669,7 +665,6 @@ public async Task SendPrimitiveReturnsNullIfValueCannotBeParsedToEnum()
}

[Fact]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Trimming", "IL2066:The generic parameter of type or method has a DynamicallyAccessedMembersAttribute, but the value used for it can not be statically analyzed.", Justification = "<Pending>")]
public async Task SendPrimitiveHandleEnumFlagsIfValuesAreStrings()
{
var mockHandler = new Mock<HttpMessageHandler>();
Expand Down Expand Up @@ -702,7 +697,6 @@ public async Task SendPrimitiveHandleEnumFlagsIfValuesAreStrings()
}

[Fact]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Trimming", "IL2066:The generic parameter of type or method has a DynamicallyAccessedMembersAttribute, but the value used for it can not be statically analyzed.", Justification = "<Pending>")]
public async Task SendPrimitiveHandleEnumFlagsIfValuesAreIntegers()
{
var mockHandler = new Mock<HttpMessageHandler>();
Expand Down Expand Up @@ -735,7 +729,6 @@ public async Task SendPrimitiveHandleEnumFlagsIfValuesAreIntegers()
}

[Fact]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Trimming", "IL2066:The generic parameter of type or method has a DynamicallyAccessedMembersAttribute, but the value used for it can not be statically analyzed.", Justification = "<Pending>")]
public async Task SendPrimitiveHandleEnumFlagsIfValuesAreFromEnumMember()
{
var mockHandler = new Mock<HttpMessageHandler>();
Expand Down Expand Up @@ -768,7 +761,6 @@ public async Task SendPrimitiveHandleEnumFlagsIfValuesAreFromEnumMember()
}

[Fact]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Trimming", "IL2066:The generic parameter of type or method has a DynamicallyAccessedMembersAttribute, but the value used for it can not be statically analyzed.", Justification = "<Pending>")]
public async Task SendPrimitiveReturnsNullIfFlagValueCannotBeParsedToEnum()
{
var mockHandler = new Mock<HttpMessageHandler>();
Expand Down

0 comments on commit 006bdfc

Please sign in to comment.