#How to call an ApplicationInsights extension method.

4 messages · Page 1 of 1 (latest)

ember token
#

I have the following script that loads the ApplicationInsights DLL from the 2.22 DLL. Everything works except the last call of the StartOperation Extension method.
I would appreciate any ideas.
`
$ApplicationInsightsDllLocation = "B:\Microsoft.ApplicationInsights.dll"

if (-not (([AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.Location -like "applicationinsights.2.22." }).Count -eq 1)) {
[Reflection.Assembly]::LoadFile($ApplicationInsightsDllLocation)
}

$TelemetryConfiguration = [Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration]::new()
$TelemetryConfiguration.ConnectionString = Get-ConnectionString
$TelemetryClient = [Microsoft.ApplicationInsights.TelemetryClient]::new($TelemetryConfiguration)

#This call works
$TelemetryClient.TrackEvent("Event Name")

#This call fails with the following error
$Operation = [Microsoft.ApplicationInsights.Extensibility.Implementation.OperationTelemetryExtensions]::StartOperation($TelemetryClient, "Operation Name")
<#
InvalidOperation: B:\Telemetry\Telemetry.ps1:34:22
Line |
34 | … Operation = [Microsoft.ApplicationInsights.Extensibility.Implementati …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Unable to find type [Microsoft.ApplicationInsights.Extensibility.Implementation.OperationTelemetryExtensions].
#>
`

snow canyon
#

The namespace is wrong.
[Microsoft.ApplicationInsights.TelemetryClientExtensions]::StartOperation

#

It's a generic method so unless you have PS7.3+ you'll have to use reflection to get at it