Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a Class-Library project in .net6, and then imported some existing codes in Framework 4.0. For the 2 lines below
C#
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;

I got
C#
Error CS0234 the type or namespace name does not exist ..

Then I revised the .csproj and added
<PropertyGroup>
  <UseWindowsForms>true</UseWindowsForms>
  ...
</PropertyGroup>

<itemgroup>
<comreference include="Microsoft.Office.Excel.dll">
<guid>00020813-0000-0000-c000-000000000046
<versionmajor>1
<versionminor>9
<wrappertool>tlbimp
<lcid>0
<isolated>false


The error for the "Excel" one is gone, but the one for "Windows.Forms" still exists. How to resolve this problem. Thanks if you can help.

What I have tried:

Error CS0234 the type or namespace name does not exist ... for using System.Windows.Forms;
Posted

1 solution

Chances are, your csproj file has the SDK set to Microsoft.NET.Sdk. Change <Project Sdk="Microsoft.NET.Sdk"> to <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">. That should sort things out for you about System.Windows.Forms.
 
Share this answer
 
Comments
s yu 3-May-24 9:00am    
Great! Thanks to Pete!
Pete O'Hanlon 3-May-24 9:01am    
My pleasure. I take it that's sorted for you now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900