andre_ss6
andre_ss6

Reputation: 1255

'Forms' is not a member of 'Windows'

I tried to change the Target Framework on my app recently from .NET Framework 4.5 to 4.5.2, but if I do I get the following error when trying to build: "'Forms' is not a member of 'Windows'" (that is, System.Windows.Forms). Changing to 4.5.1 works normally. I'm using Visual Studio 2013 Ultimate.

Upvotes: 22

Views: 30675

Answers (4)

gregmac
gregmac

Reputation: 25251

I ran into this with an application still targeted to .NET 4.0, where it failed on one (new) build server, but ran on my older ones.

I narrowed it down to the .NET 4.0 Targeting Pack only being installed on the old build servers. Targeting pack is included in Visual Studio, or the Windows 7.1 SDK. It is for some reason not distributed separately, and with support ending for .NET 4, 4.5 and 4.5.1, I don't suspect this is likely to change. Because my older servers have been around a couple years, they've gone through in-place upgrades and so had the targeting pack already.

When you install Windows 7.1 SDK on Server 2012R2, it complains something to the effect of "A pre-release version of .NET 4 is installed, please install the RTM version". As far as I can tell, it's simply because a newer version) is installed -- Server 2012R2 comes with 4.5.1. I tried to uninstall all newer versions, but was unable to get the SDK to install the targeting pack.

So to install:

You should now have a %programfiles(x86)%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\ folder with the 4.0 stuff.

(EXTUI=1 bypasses the restriction that it can't be installed separately).

This allowed me to compile projects still targeting 4.0 (or re-build old revisions/branches that were targeting it at the time).

Upvotes: 2

krishna chaithanya
krishna chaithanya

Reputation: 89

Make sure that you add System in front of the Windows.Form.

Upvotes: 7

Stefano Leoni
Stefano Leoni

Reputation: 101

I had the same problem, me too with Windows.Forms.DialogResult enumeration values.

The project automatically imports System and System.Windows.Forms namespaces and worked fine up to 4.5.1.

In 4.5.2 I had to remove Windows.Forms. and just leave DialogResult.Ok (or whatever else) in my code, it seems to be a problem with namespaces resolution.

Upvotes: 10

user3967313
user3967313

Reputation: 411

I had this error when changing to 4.5.2.

In my case the error was related to a MessageBox ... I replaced: "Windows.Forms.DialogResult.Yes" (which caused the same error message) with "System.Windows.Forms.DialogResult.Yes" which did the trick.

Upvotes: 41

Related Questions