The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

1.8k views Asked by At

I am using Visual Studio 2019 and have a console application running some selenium tests with target framework .NET core 3.1. I recently added code to use Windows forms to upload a file in my application.

System.Windows.Forms.SendKeys.SendWait(absolutePath);
System.Windows.Forms.SendKeys.SendWait("{Enter}");

When I built it, I got below error: The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

So I googled and updated my project file to add below two tags in PropertyGroup:

<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>

And hurray, it stopped complaining locally. However, when I build the application in Teamcity, I get the same error. Does anyone know why would this happen. I googled more and everyone was talking about adding assembly references. But I don't have an option to Add references in Visual Studio.

MissingAssemblyReferences:

MissingAssemblyReferences

I tried adding it as a COM dependency, that didn't work either.

However, I do see that under Dependencies > Frameworks> System.Windows.Forms is available.

Frameworks:

Frameworks

Can anyone please help me understand why is it still complaining.

Again, it works fine locally in Visual Studio and on command line, is an issue ONLY in Teamcity. The command being run in Teamcity is below:

"C:\Program Files\dotnet\dotnet.exe" build <myTestApp>.sln @C:\BuildAgent\temp\agentTmp\a84ed99789454a3fa1f0d0028fcff404.rsp

Thanks in advance!

1

There are 1 answers

0
Manu On

I finally figured it out from the answer in this post .Net core 3: manually adding framework dependencies.

I had to include a framework reference to Microsoft.AspNetCore.App in the project file as below:

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>