question

StephenRichter-0656 avatar image
0 Votes"
StephenRichter-0656 asked DanielZhang-MSFT answered

why error: namespace name PrintDialog could not be found?

How can I write code using vscode and dotnet command line that uses the PrintDialog class?

using vscode and .net sdk, I am trying to compile code that uses the PrintDialog class. In the vscode editor the code highlights with the error. And when I run dotnet run I get the message

error CS0246: The type or namespace name 'PrintDialog' could not be found (are you missing
a using directive or an assembly reference?) [C:\web\tester\dotnet\ch4\ch4.csproj]

I ran dotnet add package System.Windows.Forms . The result was :

error: There are no versions available for the package 'System.Windows.Forms'.

I did install the .NET Framework 4.8. But there was no "dotnet" command line. So I uninstalled and installed .NET 5.0 instead.

How can I write code using vscode and dotnet command line that uses the PrintDialog class?

thanks,

windows-forms
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.

1 Answer

DanielZhang-MSFT avatar image
1 Vote"
DanielZhang-MSFT answered

Hi StephenRichter-0656,
First, Visual Studio Code supports .NET Framework building and debugging projects, but it is very limited.
And the C# extension supports limited full .NET framework debugging. It can only debug 64-bit applications with portable PDBs.
You need to modify your .csproj file to manually manage your NuGet packages, more details please refer to the Mario Figueiredo's answer.
Here are also some similar threads and hope helpful to you.
System.Windows.Forms assembly reference in VS Code
Manually Setting up a .NET Framework Project using VS Code
Finally, I would advice you to use Visual Studio (the community version would suffice). It has much better support for any .NET framework development.
Best Regards,
Daniel Zhang


If the response 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.


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.