Using the last example to generate a random class name looks to be the simplest solution.
https://stackoverflow.com/questions/25730978/powershell-add-type-cannot-add-type-already-exist
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello everybody.
I tried this:
$code = @"
using System;
namespace HelloWorld
{
public class Program
{
public static void Main(){
Console.WriteLine("Hello world!");
}
}
}
"@
Add-Type -TypeDefinition $code -Language CSharp
iex "[HelloWorld.Program]::Main()"
It work.
But when I change the "$code" variable script and "add-type" it secend time it show me an error.
Why i can't update secend time my script?
How can i do it?
Thanks for help.
Using the last example to generate a random class name looks to be the simplest solution.
https://stackoverflow.com/questions/25730978/powershell-add-type-cannot-add-type-already-exist
Hi,
You have to use another type name because it must be unique within a session and can neither be updated nor removed.
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.