Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InitializeServiceClient ServiceClient<T> mismatch exception when adding to list #7007

Closed
danielkboyer opened this issue Jul 23, 2019 · 4 comments
Labels
needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team.

Comments

@danielkboyer
Copy link

danielkboyer commented Jul 23, 2019

Describe the bug
I am using Azure Data Factory management client and trying to connect to it through an azure functions app. It seems like when initializing the service client I get an invalid type when it tries to add to the array.

Exception or Stack Trace
"Exception while executing function: ScheduleNotifications -> Attempted to access an element as a type incompatible with the array.",
"errorDetails": "Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: ScheduleNotifications ---> System.ArrayTypeMismatchException : Attempted to access an element as a type incompatible with the array.\r\n at System.Collections.Generic.List1.Add(T item)\r\n at Microsoft.Azure.Management.DataFactory.DataFactoryManagementClient.Initialize()\r\n at Microsoft.Azure.Management.DataFactory.DataFactoryManagementClient..ctor(DelegatingHandler[] handlers)\r\n at Microsoft.Azure.Management.DataFactory.DataFactoryManagementClient..ctor(ServiceClientCredentials credentials,DelegatingHandler[] handlers)\r\n at DataFactorySDK.FactoryAuth.GetClient() at C:\\Users\\dedaq\\source\\repos\\DataFactorySDK\\DataFactorySDK\\FactoryAuth.cs : 44\r\n at ScheduleBatch.ScheduleNotifications.ScheduleDelivery(String location,String deliveryDate,String filePath,List1 intervals,TraceWriter log)\r\n at async ScheduleBatch.ScheduleNotifications.Run(HttpRequestMessage req,TraceWriter log)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker2.InvokeAsync[TReflected,TReturnValue](Object instance,Object[] arguments)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeAsync(IFunctionInvoker invoker,ParameterHelper parameterHelper,CancellationTokenSource timeoutTokenSource,CancellationTokenSource functionCancellationTokenSource,Boolean throwOnTimeout,TimeSpan timerInterval,IFunctionInstance instance)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstance instance,ParameterHelper parameterHelper,TraceWriter traceWriter,CancellationTokenSource functionCancellationTokenSource)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??) \r\n End of inner exception\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(??)\r\n at async Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance,CancellationToken cancellationToken)\r\n at Microsoft.Azure.WebJobs.Host.Executors.ExceptionDispatchInfoDelayedException.Throw()\r\n at async Microsoft.Azure.WebJobs.JobHost.CallAsync(??)\r\n at async Microsoft.Azure.WebJobs.Script.ScriptHost.CallAsync(String method,Dictionary2 arguments,CancellationToken cancellationToken)\r\n at async Microsoft.Azure.WebJobs.Script.WebHost.WebScriptHostManager.HandleRequestAsync(FunctionDescriptor function,HttpRequestMessage request,CancellationToken cancellationToken)\r\n at async Microsoft.Azure.WebJobs.Script.Host.FunctionRequestInvoker.ProcessRequestAsync(HttpRequestMessage request,CancellationToken cancellationToken,WebScriptHostManager scriptHostManager,WebHookReceiverManager webHookReceiverManager)\r\n at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.<>c__DisplayClass3_0.b__0(??)\r\n at async Microsoft.Azure.WebJobs.Extensions.Http.HttpRequestManager.ProcessRequestAsync(HttpRequestMessage request,Func`3 processRequestHandler,CancellationToken cancellationToken)\r\n at async Microsoft.Azure.WebJobs.Script.WebHost.Controllers.FunctionsController.ExecuteAsync(HttpControllerContext controllerContext,CancellationToken cancellationToken)\r\n at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n at async System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.WebScriptHostHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n at async Microsoft.Azure.WebJobs.Script.WebHost.Handlers.SystemTraceHandler.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)\r\n at async System.Web.Http.HttpServer.SendAsync(HttpRequestMessage request,CancellationToken cancellationToken)"

To Reproduce
Try to create an Azure Data Factory Client inside of an azure function app. Just initialize it with tokens from the azure portal ( I ran it locally and triggered with postman).

Code Snippet

public DataFactoryManagementClient GetClient()
        {
            var context = new AuthenticationContext("https://login.windows.net/" + tenantID);
            ClientCredential cc = new ClientCredential(applicationId, authenticationKey);
            AuthenticationResult result = context.AcquireTokenAsync(
                "https://management.azure.com/", cc).Result;
            // This is the line that it breaks on... it seems like it's not calling initializeServiceClient with 
           //the right types
            ServiceClientCredentials cred = new TokenCredentials(result.AccessToken);
            return  new DataFactoryManagementClient(cred)
            {
                SubscriptionId = subscriptionId
            };

        }
@triage-new-issues triage-new-issues bot added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jul 23, 2019
@danielkboyer
Copy link
Author

I fixed this by lowering the version of the azure data factory .net sdk. I think it's a dependency issue associated with azure functions and not with the ServiceClient.

@graham-saunders
Copy link

@danielkboyer what version did you downgrade to in the Microsoft.AZure.Search.Data nuget?

@danielkboyer
Copy link
Author

danielkboyer commented Sep 30, 2019

@graham-saunders I didn't use Microsoft.Azure.Search.Data nuget but I found that lowering newtonsoft to version 10 fixed it for me, this is inside of a different thread here, my problem was azure functions and not ServiceClient

@graham-saunders
Copy link

@danielkboyer thanks for getting back so quickly; that thread was really helpful

@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team.
Projects
None yet
Development

No branches or pull requests

2 participants