How to load assembly path in the new runtime experience in Automation Accounts' runbooks?

Alibek Cholponbaev 20 Reputation points
2024-04-25T10:08:10.14+00:00

We have a runbook that we use to log to Application Insights. We use it for making logs both from Azure and Hybrid workers. In hybrid workers the logging works correctly, but in Azure it fails with

Cannot find type [Microsoft.ApplicationInsights.TelemetryClient]: verify that the assembly containing this type is loaded

Here's how we load the assembly to use the Microsoft.ApplicationInsights module in the code:

$AssemblyPathAzure = "C:\Modules\User\Microsoft.ApplicationInsights\Microsoft.ApplicationInsights.dll"
$AssemblyPathHybridWorker = "C:\Program Files\WindowsPowerShell\Modules\microsoft.applicationinsights.2.20.0\lib\net46\Microsoft.ApplicationInsights.dll"
try {Add-Type -Path $AssemblyPathAzure}
catch  { $_.Exception.LoaderExceptions }

try {Add-Type -Path $AssemblyPathHybridWorker}
catch  { $_.Exception.LoaderExceptions }

I've also tried the following path:

$AssemblyPathAzure = "C:\Modules\Global\Azure\Compute\Microsoft.ApplicationInsights.dll"

Both don't work in Azure.

I have a feeling that the import from "C:\Modules\User\Microsoft.ApplicationInsights\Microsoft.ApplicationInsights.dll" used to work before Accounts migrated to the new Runtime Experience

Could you help out with this issue?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,124 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,081 questions
0 comments No comments
{count} votes