microsoftgraph / msgraph-sdk-dotnet

Microsoft Graph Client Library for .NET!
https://graph.microsoft.com
Other
704 stars 252 forks source link

Graph Service Client EndDateTime invalid type #1903

Closed Will-Kerwin closed 1 year ago

Will-Kerwin commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

I am trying to send a request through the graph sdk v5.10.0 it continously returns a failure saying one of the properties is invalid. I am trying to create a new client secret for an app registration using

var requestBody = new Microsoft.Graph.Applications.Item.AddPassword.AddPasswordPostRequestBody
{
    PasswordCredential = new PasswordCredential
    {
        DisplayName = "Password friendly name",
                 EndDateTime = DateTimeOffset.Now.AddMonths(2)
    },
};
var result = await graphClient.Applications["{application-id}"].AddPassword.PostAsync(requestBody);

Each time it fails with the following exception 'Microsoft.Graph.Models.ODataErrors.ODataError' and inner exception of

Result: Function 'AppRegistrationRotation', Invocation id '6a804bf3-e689-4179-9a2b-a864e92b828d': An exception was thrown by the invocation.
[2023-05-15T14:01:34.318Z] Exception: System.AggregateException: One or more errors occurred. (String '1559082102' was not recognized as a valid DateTime.)

I am using managed identity to authenticate on an azure linux function app. for local testing i am using my personal account with the required permissions consented. I have attempted on both and none have worked.

MS Learn

To Reproduce Steps to reproduce the behavior:

  1. Run the following code with _graph being GraphServiceClient and appId being any valid app registration client id in azure tennant.
            var requestBody = new AddPasswordPostRequestBody
            {
                PasswordCredential = new PasswordCredential
                {
                    DisplayName = "Automated Secret Rotation",
                    EndDateTime = DateTimeOffset.Now.AddMonths(2)
                }
            };
            var result = await _graph.Applications[appId].AddPassword.PostAsync(requestBody);
  2. the request should return a valid response and the response body for this graph request

Expected behavior A clear and concise description of what you expected to happen. I expect this code to pass through a datetime offset of two months from the current date and it to create a client secret with the desired app registration and return that data.

Screenshots If applicable, add screenshots to help explain your problem. not a screenshot but full stacktrace

An error occured which meant secret could not be rotated
[2023-05-15T14:01:34.278Z] Result: An error occured which meant secret could not be rotated
[2023-05-15T14:01:34.278Z] Exception: Microsoft.Graph.Models.ODataErrors.ODataError: Exception of type 'Microsoft.Graph.Models.ODataErrors.ODataError' was thrown.
[2023-05-15T14:01:34.278Z]    at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes)
[2023-05-15T14:01:34.278Z]    at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
[2023-05-15T14:01:34.278Z]    at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
[2023-05-15T14:01:34.278Z]    at Microsoft.Graph.Applications.Item.AddPassword.AddPasswordRequestBuilder.PostAsync(AddPasswordPostRequestBody body, Action`1 requestConfiguration, CancellationToken cancellationToken)
[2023-05-15T14:01:34.278Z]    at SecretRotation.Functions.AppRegistration.AppRegistrationRotation.Run(MyEvent`1 input) in /Users/williamkerwin/Projects/Microservices/SecretRotation.Functions/SecretRotation.Functions/AppRegistration/AppRegistrationRotation.cs:line 66
[2023-05-15T14:01:34.278Z] Stack:    at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes)
[2023-05-15T14:01:34.278Z]    at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
[2023-05-15T14:01:34.278Z]    at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
[2023-05-15T14:01:34.278Z]    at Microsoft.Graph.Applications.Item.AddPassword.AddPasswordRequestBuilder.PostAsync(AddPasswordPostRequestBody body, Action`1 requestConfiguration, CancellationToken cancellationToken)
[2023-05-15T14:01:34.278Z]    at SecretRotation.Functions.AppRegistration.AppRegistrationRotation.Run(MyEvent`1 input) in /Users/williamkerwin/Projects/Microservices/SecretRotation.Functions/SecretRotation.Functions/AppRegistration/AppRegistrationRotation.cs:line 66.
[2023-05-15T14:01:34.318Z] Function 'AppRegistrationRotation', Invocation id '6a804bf3-e689-4179-9a2b-a864e92b828d': An exception was thrown by the invocation.
[2023-05-15T14:01:34.318Z] Result: Function 'AppRegistrationRotation', Invocation id '6a804bf3-e689-4179-9a2b-a864e92b828d': An exception was thrown by the invocation.
[2023-05-15T14:01:34.318Z] Exception: System.AggregateException: One or more errors occurred. (String '1559082102' was not recognized as a valid DateTime.)
[2023-05-15T14:01:34.318Z]  ---> System.FormatException: String '1559082102' was not recognized as a valid DateTime.
[2023-05-15T14:01:34.319Z]    at System.DateTime.Parse(String s)
[2023-05-15T14:01:34.319Z]    at SecretRotation.Functions.AppRegistration.AppRegistrationRotation.Run(MyEvent`1 input) in /Users/williamkerwin/Projects/Microservices/SecretRotation.Functions/SecretRotation.Functions/AppRegistration/AppRegistrationRotation.cs:line 92
[2023-05-15T14:01:34.319Z]    at Microsoft.Azure.Functions.Worker.Invocation.VoidTaskMethodInvoker`2.InvokeAsync(TReflected instance, Object[] arguments) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\VoidTaskMethodInvoker.cs:line 22
[2023-05-15T14:01:34.319Z]    --- End of inner exception stack trace ---
[2023-05-15T14:01:34.319Z]    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[2023-05-15T14:01:34.319Z]    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
[2023-05-15T14:01:34.319Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker`2.<>c.<InvokeAsync>b__6_0(Task`1 t) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionInvoker.cs:line 32
[2023-05-15T14:01:34.319Z]    at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
[2023-05-15T14:01:34.319Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-05-15T14:01:34.319Z] --- End of stack trace from previous location ---
[2023-05-15T14:01:34.319Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-05-15T14:01:34.319Z]    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
[2023-05-15T14:01:34.319Z] --- End of stack trace from previous location ---
[2023-05-15T14:01:34.319Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 45
[2023-05-15T14:01:34.319Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2023-05-15T14:01:34.319Z]    at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 77
[2023-05-15T14:01:34.319Z] Stack:    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[2023-05-15T14:01:34.319Z]    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
[2023-05-15T14:01:34.319Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker`2.<>c.<InvokeAsync>b__6_0(Task`1 t) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionInvoker.cs:line 32
[2023-05-15T14:01:34.319Z]    at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
[2023-05-15T14:01:34.319Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-05-15T14:01:34.319Z] --- End of stack trace from previous location ---
[2023-05-15T14:01:34.319Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-05-15T14:01:34.319Z]    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
[2023-05-15T14:01:34.319Z] --- End of stack trace from previous location ---
[2023-05-15T14:01:34.319Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 45
[2023-05-15T14:01:34.319Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2023-05-15T14:01:34.319Z]    at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 77.
[2023-05-15T14:01:34.514Z] Executed 'Functions.AppRegistrationRotation' (Failed, Id=6a804bf3-e689-4179-9a2b-a864e92b828d, Duration=20593ms)
[2023-05-15T14:01:34.514Z] System.Private.CoreLib: Exception while executing function: Functions.AppRegistrationRotation. System.Private.CoreLib: Result: Failure
[2023-05-15T14:01:34.514Z] Exception: System.AggregateException: One or more errors occurred. (String '1559082102' was not recognized as a valid DateTime.)
[2023-05-15T14:01:34.514Z]  ---> System.FormatException: String '1559082102' was not recognized as a valid DateTime.
[2023-05-15T14:01:34.514Z]    at System.DateTime.Parse(String s)
[2023-05-15T14:01:34.514Z]    at SecretRotation.Functions.AppRegistration.AppRegistrationRotation.Run(MyEvent`1 input) in /Users/williamkerwin/Projects/Microservices/SecretRotation.Functions/SecretRotation.Functions/AppRegistration/AppRegistrationRotation.cs:line 92
[2023-05-15T14:01:34.514Z]    at Microsoft.Azure.Functions.Worker.Invocation.VoidTaskMethodInvoker`2.InvokeAsync(TReflected instance, Object[] arguments) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\VoidTaskMethodInvoker.cs:line 22
[2023-05-15T14:01:34.514Z]    --- End of inner exception stack trace ---
[2023-05-15T14:01:34.515Z]    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[2023-05-15T14:01:34.515Z]    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
[2023-05-15T14:01:34.515Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker`2.<>c.<InvokeAsync>b__6_0(Task`1 t) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionInvoker.cs:line 32
[2023-05-15T14:01:34.515Z]    at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
[2023-05-15T14:01:34.515Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-05-15T14:01:34.515Z] --- End of stack trace from previous location ---
[2023-05-15T14:01:34.515Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-05-15T14:01:34.515Z]    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
[2023-05-15T14:01:34.515Z] --- End of stack trace from previous location ---
[2023-05-15T14:01:34.515Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 45
[2023-05-15T14:01:34.515Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2023-05-15T14:01:34.515Z]    at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 77
[2023-05-15T14:01:34.515Z]    at Microsoft.Azure.Functions.Worker.Handlers.InvocationHandler.InvokeAsync(InvocationRequest request) in D:\a\_work\1\s\src\DotNetWorker.Grpc\Handlers\InvocationHandler.cs:line 88
[2023-05-15T14:01:34.515Z] Stack:    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[2023-05-15T14:01:34.515Z]    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
[2023-05-15T14:01:34.515Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionInvoker`2.<>c.<InvokeAsync>b__6_0(Task`1 t) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionInvoker.cs:line 32
[2023-05-15T14:01:34.515Z]    at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
[2023-05-15T14:01:34.515Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-05-15T14:01:34.515Z] --- End of stack trace from previous location ---
[2023-05-15T14:01:34.515Z]    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
[2023-05-15T14:01:34.515Z]    at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
[2023-05-15T14:01:34.515Z] --- End of stack trace from previous location ---
[2023-05-15T14:01:34.515Z]    at Microsoft.Azure.Functions.Worker.Invocation.DefaultFunctionExecutor.ExecuteAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\Invocation\DefaultFunctionExecutor.cs:line 45
[2023-05-15T14:01:34.515Z]    at Microsoft.Azure.Functions.Worker.OutputBindings.OutputBindingsMiddleware.Invoke(FunctionContext context, FunctionExecutionDelegate next) in D:\a\_work\1\s\src\DotNetWorker.Core\OutputBindings\OutputBindingsMiddleware.cs:line 13
[2023-05-15T14:01:34.515Z]    at Microsoft.Azure.Functions.Worker.FunctionsApplication.InvokeFunctionAsync(FunctionContext context) in D:\a\_work\1\s\src\DotNetWorker.Core\FunctionsApplication.cs:line 77
[2023-05-15T14:01:34.515Z]    at Microsoft.Azure.Functions.Worker.Handlers.InvocationHandler.InvokeAsync(InvocationRequest request) in D:\a\_work\1\s\src\DotNetWorker.Grpc\Handlers\InvocationHandler.cs:line 88.

Desktop (please complete the following information):

andrueastman commented 1 year ago

Thanks for raising this @Will-Kerwin

Unfortunately, executing the code sample shared results in a successful request when making a call with the SDK.

Any chance you are able to catch the error thrown and share the detailed error response from the API by following the guidance at the link below?

https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/upgrade-to-v5.md#error-handling

Will-Kerwin commented 1 year ago

thank you, i have misunderstood what was meant by app id and oid. the advice with capturing the odata error helped me find this.