How does ThrowTerminatingError work in C#?

Question:

I have the following cmdlet written in C#, it basically just throws an error:

I’m assuming (I could be wrong), this is the equivalent in PowerShell)

The PowerShell version behaves as expected:

The C# version however, crashes, with the following information:

What am I doing wrong?

Answer:

Can confirm, it’s an environment problem, and a damn wierd one at that.

Basically if you follow the instructions here, then go to debug any binary modules, if you call ThrowTerminatingError, it crashes with PipelineStoppedException.

Now I need some kind of fix/workaround.

Edit: Found a fix, check ‘enable native code debugging’ in the project properties.

Source:

How does ThrowTerminatingError work in C#? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply