Share via

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
28 June 2021, 4:51 pm

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 Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,628 questions
{count} votes

Accepted answer
  1. Sam of Simple Samples 5,551 Reputation points
    28 June 2021, 4:52 pm

    Change Sytem to System.


1 additional answer

Sort by: Most helpful
  1. MotoX80 35,626 Reputation points
    28 June 2021, 7:33 pm

    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.