question

Filip-2434 avatar image
0 Votes"
Filip-2434 asked SimpleSamples commented

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

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
a.png (104.4 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am not familiar with Powershell but I tried your code. For the C# code you have you do not need System.Windows.Forms. So I removed the using for it and then the code works.

0 Votes 0 ·
SimpleSamples avatar image
0 Votes"
SimpleSamples answered SimpleSamples commented

Change Sytem to System.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello.
Oh, I see but it's still not the problem.
It still doesn't work because it show another error.

0 Votes 0 ·

I answered the question about the problem you posted. Another error is a new problem.

0 Votes 0 ·
MotoX80 avatar image
0 Votes"
MotoX80 answered

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/

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.