why error: namespace name PrintDialog could not be found?

Stephen Richter 21 Reputation points
2021-05-11T00:25:21.69+00:00

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,

Developer technologies | Windows Forms
0 comments No comments
{count} votes

Accepted answer
  1. Daniel Zhang-MSFT 9,651 Reputation points
    2021-05-11T02:58:28.793+00:00

    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.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.