-
Notifications
You must be signed in to change notification settings - Fork 60
Unable to run in azure functions #234
Comments
@Shadoxity thank you for opening this issue. More than likely this error has to deal with how the |
@Shadoxity what type of service plan are you using? I have been testing using a consumption plan and everything is working as excepted. Also, would you be able to share the value for the The following is a screenshot of my configuration where this is currently working Having this information will be extremely helpful in reproducing the error |
Hey @IsaiahWilliams, thanks for your help. |
I got the same error running the code in a consumption azure function. |
@Shadoxity thank you for sharing thia information. This is an interesting issue, that I am working to reproduce. Currently the only difference I see is how the dependencies are managed. You can read about how I got the module installed at Let me dig into this further to see if I can find the root cause. |
@IsaiahWilliams How do I add the modules in that method? Where is the requirements.psd1 file? Can you share the contents of yours and I can try that way |
@Shadoxity I am using the Azure Functions extension for Visual Studio Code to deploy. The following figure shows what is being deployed The following figure shows what was actually deployed Note the .IdentityService directory was created by the module and is not part of the deployment. All of this means you can create the requirements.psd1 file in the root of the wwwroot direct. With my testing I used the following
The Az module is not necessary, it was just part of the template I used to generate my test app. |
I removed the modules directory, added the partnercenter into the requirements.psd1 file. Restarted the automation and ran again. still gives the same error. For reference this is what I am trying to run and it works via powershell normally. $client_id = "" $token = New-PartnerAccessToken -ApplicationId $client_Id -Credential $credential -RefreshToken $refreshToken -Scopes 'https://api.partnercenter.microsoft.com/user_impersonation' -ServicePrincipal -Tenant $tenant_id write-output $token |
@Shadoxity that is similar to what my test script is doing. I have found a way to reproduce the issue, and if you need a temporary work around use the following for your requirements.psd1 # This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
'Az' = '3.*'
'PartnerCenter' = '3.*'
} This particular issue will be resolved, but I wanted to make sure you are not blocked while I work to pinpoint the exact root cause. |
That is already what is on my requirements file, unless I'm missing something?
That's what I copied from yours and still got the error?
This is my current file
# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
'Az' = '3.*'
'PartnerCenter' = '3.*'
}
|
@Shadoxity through my testing it should take a couple of minutes to work as expected. Also, I wanted to share that I recently made some changes to the way the |
@IsaiahWilliams How do you mean a couple mins? Like open the app and let it sit for a while? Does this mean it will fail running on a timer? I have opened it again and still getting the same errors Exception: Cannot bind argument to parameter 'InputObject' |
@Shadoxity if the above does not work, then you can try including the following before the if($env:LOCALAPPDATA)
{
$path = "$($env:LOCALAPPDATA)\.IdentityService"
if(-not (Test-Path $path))
{
New-Item -Path "$path\msal.cache" -ErrorAction Stop -Force | Out-Null
}
} Once the next update, which will be release 3.0.2, is published you will no longer need this. |
@IsaiahWilliams I tried adding that in and unfortunately it made no difference. Still get the same error :( |
@IsaiahWilliams and just to note, if I run the same code in an azure automation runbook it works perfectly fine. I guess I may use things that way till this is fixed considering we cannot find a work around to make it work? |
@Shadoxity I decided to release the next version early to help unblock a handful of scenarios. Starting with version 3.0.3 this issue has been addressed. |
I am trying to set up a number of scripts in azure functions to run maintenance etc on our customer tenants but I cannot get it to produce a token.
The same commands work fine when running from powershell on my machine
Steps to reproduce
Create an azure function, load the modules for partner center
Using command
$token = New-PartnerAccessToken -ApplicationId $client_Id -Credential $credential -RefreshToken $refreshToken -Scopes 'https://api.partnercenter.microsoft.com/user_impersonation' -ServicePrincipal -Tenant $tenant_id
Fails
Expected behavior
Create a token to use for partner center powershell access
Actual behavior
Error message
ERROR: New-PartnerAccessToken : Error reading JObject from JsonReader. Path '', line 0, position 0.
At D:\home\site\wwwroot\RefreshToken\run.ps1:29 char:1
Script stack trace:
at , D:\home\site\wwwroot\RefreshToken\run.ps1: line 29
Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Path '', line 0, position 0.
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Parse(String json)
at Microsoft.Store.PartnerCenter.PowerShell.Commands.NewPartnerAccessToken.b__54_0()
at Microsoft.Store.PartnerCenter.PowerShell.Utilities.ConcurrencyTaskScheduler.RunConcurrentTaskAsync(Int64 taskId, Task task)
Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: ERROR: New-PartnerAccessToken : Error reading JObject from JsonReader. Path '', line 0, position 0.
At D:\home\site\wwwroot\RefreshToken\run.ps1:29 char:1
Script stack trace:
at , D:\home\site\wwwroot\RefreshToken\run.ps1: line 29
Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Path '', line 0, position 0.
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Parse(String json)
at Microsoft.Store.PartnerCenter.PowerShell.Commands.NewPartnerAccessToken.b__54_0()
at Microsoft.Store.PartnerCenter.PowerShell.Utilities.ConcurrencyTaskScheduler.RunConcurrentTaskAsync(Int64 taskId, Task task)
Exception: Error reading JObject from JsonReader. Path '', line 0, position 0.
Stack: at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Parse(String json, JsonLoadSettings settings)
at Newtonsoft.Json.Linq.JObject.Parse(String json)
at Microsoft.Store.PartnerCenter.PowerShell.Commands.NewPartnerAccessToken.b__54_0()
at Microsoft.Store.PartnerCenter.PowerShell.Utilities.ConcurrencyTaskScheduler.RunConcurrentTaskAsync(Int64 taskId, Task task)
2019-12-23T04:29:03.193 [Error] ERROR: Trace-PipelineObject : Cannot bind argument to parameter 'InputObject' because it is null.
Script stack trace:
at , D:\home\site\wwwroot\RefreshToken\run.ps1: line 31
System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'InputObject' because it is null.
at System.Management.Automation.CmdletParameterBinderController.BindValueFromPipeline(PSObject inputToOperateOn, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingStateInParameterSet(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets)
at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingState(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets)
at System.Management.Automation.CmdletParameterBinderController.BindPipelineParametersPrivate(PSObject inputToOperateOn)
at System.Management.Automation.CmdletParameterBinderController.BindPipelineParameters(PSObject inputToOperateOn)
at System.Management.Automation.CommandProcessor.Read()
Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: ERROR: Trace-PipelineObject : Cannot bind argument to parameter 'InputObject' because it is null.
Script stack trace:
at , D:\home\site\wwwroot\RefreshToken\run.ps1: line 31
System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter 'InputObject' because it is null.
at System.Management.Automation.CmdletParameterBinderController.BindValueFromPipeline(PSObject inputToOperateOn, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingStateInParameterSet(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets)
at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingState(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets)
at System.Management.Automation.CmdletParameterBinderController.BindPipelineParametersPrivate(PSObject inputToOperateOn)
at System.Management.Automation.CmdletParameterBinderController.BindPipelineParameters(PSObject inputToOperateOn)
at System.Management.Automation.CommandProcessor.Read()
Exception: Cannot bind argument to parameter 'InputObject' because it is null.
Stack: at System.Management.Automation.CmdletParameterBinderController.BindValueFromPipeline(PSObject inputToOperateOn, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingStateInParameterSet(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets)
at System.Management.Automation.CmdletParameterBinderController.BindUnboundParametersForBindingState(PSObject inputToOperateOn, CurrentlyBinding currentlyBinding, UInt32 validParameterSets)
at System.Management.Automation.CmdletParameterBinderController.BindPipelineParametersPrivate(PSObject inputToOperateOn)
at System.Management.Automation.CmdletParameterBinderController.BindPipelineParameters(PSObject inputToOperateOn)
at System.Management.Automation.CommandProcessor.Read()
Diagnostic logs
Environment
Azure functions with partner center and msonline module loaded.
Tried using version 2 and 3
The text was updated successfully, but these errors were encountered: