Consider the following PowerShell snippet:
$csharpString = @\"
using System;
public sealed class MyClass
{
public MyClass() { }
public override stri
Actually, none of this is required. Add-Type maintains a cache of any code that you submit to it, along with the resulting type. If you call Add-Type twice with the same code, then it won't bother compiling the code and will just return the type from last time.
You can verify this by just running an Add-Type call twice in a row.
The reason you got the error message in the example above is that you changed the code between calls to Add-Type. While the solution above makes that error go away in this situation, it also means that you're working with an older definition of the type that probably isn't acting the way you think it is.