Azure / Azure/azure-powershell

Error when executing Automation Runbook using Workflow: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

Open
#21,129 1 comment 0 reactions 0 assignees View on GitHub
Accounts Azure PS Team customer-reported Investigate :mag: potential-pruning
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
3d 14h
Merged PRs (30d)
54

Description

### Description
#### Error when executing Automation Runbook using Workflow
Trying to test a runbook using workflows (and ForEach -Parallel) targeting PowerShell Module 5.1 and I can't seem to get past the above mentioned error:

`Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.`

### Steps to reproduce
**Here is my script (automation name and RG name masked & I am passing the $RunbookName as parameter):**
```
Workflow Test-Runbook
{
Param(
[string]$RunBookName
)
ForEach -Parallel -throttle 3 ($VM in $VMs)
{
$job = Start-AzAutomationRunbook `
-AutomationAccountName "automationaccountname" `
-Name $RunBookName -ResourceGroupName "resourcegroupname"
Start-Sleep -s 3
}
}
Test-Runbook -RunBookName $RunBookName | Write-Output
```

I would like to note that I was able to execute the runbook within a function. My requirement is to execute a Foreach loop with Parallel which requires Workflow.

**Related documentation:**

- [Link 1 : Windows PowerShell Workflow Concepts](https://learn.microsoft.com/en-us/system-center/sma/overview-powershell-workflows?view=sc-sma-2022)
- [Link 2 : Learn PowerShell Workflow for Azure Automation](https://learn.microsoft.com/en-us/azure/automation/automation-powershell-workflow)

### Expected behavior

```console
Be able to execute the workflow successfully.
```

### Actual behavior

```console
`Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.`

More info based on `Resolve-AzError`:

InnerException : False
Exception : System.Management.Automation.RemoteException: Could not load file or assembly 'Newtonsoft.Json,
Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The
system cannot find the file specified.
at Microsoft.PowerShell.Activities.PSActivity.OnResumeBookmark(NativeActivityContext context,
Bookmark bookmark, Object value)
at System.Activities.Runtime.BookmarkWorkItem.Execute(ActivityExecutor executor, BookmarkManager
bookmarkManager)
Message : Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file
specified.
StackTrace : at Microsoft.PowerShell.Activities.PSActivity.OnResumeBookmark(NativeActivityContext context,
Bookmark bookmark, Object value)
at System.Activities.Runtime.BookmarkWorkItem.Execute(ActivityExecutor executor, BookmarkManager
bookmarkManager)
HelpLink :
ErrorDetails :
ErrorCategory : NotSpecified: (:) [Write-Error], RemoteException
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace :
```

Related documentation:

- [Link 1 : Windows PowerShell Workflow Concepts](https://learn.microsoft.com/en-us/system-center/sma/overview-powershell-workflows?view=sc-sma-2022)
- [Link 2 : Learn PowerShell Workflow for Azure Automation](https://learn.microsoft.com/en-us/azure/automation/automation-powershell-workflow)
```

### Error details

```console
System.Management.Automation.CommandNotFoundException: The term 'Get-Error' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandTypes commandTypes, SearchResolutionOptions searchResolutionOptions, CommandOrigin commandOrigin, ExecutionContext context)
at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)
at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)
at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)
at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
```

### Environment data

```powershell
Name Value
---- -----
PSVersion 5.1.15063.726
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.15063.726
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
```

### Visuals

image

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied Test-Runbook workflow with ForEach -Parallel under PowerShell 5.1 and review the linked Windows PowerShell Workflow and Azure Automation documentation. Done means the workflow executes successfully without the Newtonsoft.Json assembly-loading error.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.