Powershell The type or namespace name 'Sytem' could not be found (are you m issing a using directive or an assembly reference?)

Filip 831 Reputation points
2021-06-28T16:51:09.92+00:00

Hello
i tried using System.Windows.Forms; in my code but it show me an error.
What is wrong, because i want to create the form application using my namespace.
Is it possible to do?
Thanks for help.

$code = @"
using System;
using System.Windows.Forms;
namespace HelloWorld
{
public class Program
{
public static void Main(){
Console.WriteLine("Hello world!");
}
}
}
"@

Add-Type -TypeDefinition $code -Language CSharp
iex "[HelloWorld.Program]::Main()"110001-a.png

Windows for business Windows Server User experience PowerShell
{count} votes

Accepted answer
  1. Sam of Simple Samples 5,546 Reputation points
    2021-06-28T16:52:51.3+00:00

    Change Sytem to System.


1 additional answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2021-06-28T19:33:19.05+00:00

    Why are you trying to write C# code inside of Powershell? Download the free Visual Studio Community edition and use it to build GUI C# apps. It will be so much easier to develop and test.

    https://visualstudio.microsoft.com/vs/community/

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.