I am using a PowerShell script to run C # code directly in a script. I encountered an error several times. If I make any changes to the C # code in PowerShell ISE and try to run it again, I get the following error.
Add-Type : Cannot add type. The type name 'AlertsOnOff10.onOff' already exists. At C:\Users\testUser\Desktop\test.ps1:80 char:1 + Add-Type -TypeDefinition $Source -ReferencedAssemblies $Assem + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (AlertsOnOff10.onOff:String) [Add-Type], Exception + FullyQualifiedErrorId : TYPE_ALREADY_EXISTS,Microsoft.PowerShell.Commands.AddTypeCommand
The way I solved this error is to change the namespace and command to call the C # method [AlertsOnOff10.onOff]::Main("off") . Can I prevent this error without changing the namespace and method call?
c # powershell runtime-error
zingwing
source share