F#: Namespace not defined when trying to open System.Windows.Forms - winforms

I am using Visual Studio 2008 Integrated Shell with the F# CTP (October). Everything works fine, but when I am trying to open System.Windows.Forms, VS gives an error: the namespace 'Windows' is not defined.
However, it works when I try to open the namespace in F# interactive.
What am I doing wrong?

For F# Visual Studio projects you will need to right click on your project References entry and walk through the Add Reference dialog. F# Interactive includes references to several frequently used assemblies by default whereas F# application projects only get FSharp.Core, mscorlib, System, and System.Core by default.

The System.Windows.Forms namespace lives in the System.Windows.Forms.dll. You'll need to make sure it's loaded. In fsi use the following to load it from the gac.
#r "System.Windows.Forms";;
then you can use as normal
let w = new System.Windows.Forms.Form() ;;
w.Show();;
w.Close();;

Related

error LNK2019 :unresolved external symbol_main referenced in function tmainCRTsetup [duplicate]

I just installed Visual Studio 2012 express for Desktop. I can't see any place to create a GUI application with C++ ! Where is this "Windows Form Application" used to exists in Visual C++ 2010 ? Where are these drag and drop controls? I installed this because I got details telling this supports GUI intellisense (Visual C++: Unable to invoke method from another class)
It is an unsubtle hint that they want you to stop creating C++/CLI Winforms applications. The plumbing is still in place however, at least for VS2012 and VS2013. This might not be the case in a future one.
You can turn a CLR console application into a Winforms application with these steps:
Start with File + New + Project, CLR node, CLR Console Application
Project + Add New Item, UI node, Windows Form
Project + Properties, Linker, System, SubSystem = Windows
Project + Properties, Linker, Advanced, Entry Point = main
Change the pre-generated .cpp file to look like this:
#include "stdafx.h"
#include "MyForm.h"
namespace ConsoleApplication45 { // Change this!!
using namespace System;
using namespace System::Windows::Forms;
[STAThread]
int main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew MyForm());
return 0;
}
}
Note that you'll need to change the namespace name to your project name. Press F5 to test. You can design the form as normal once everything checks out.
NOTE, Visual Studio 2015 has a nasty static initialization order bug in the CRT that can cause the app to crash instantly with an AVE at startup if the project contains any native C++ code. As yet an unfixed bug, the somewhat inevitable hazard of having these project templates removed. A possible workaround is to change the Entry Point (4th bullet).
For a project that targets x86, copy paste this string:
?mainCRTStartupStrArray##$$FYMHP$01AP$AAVString#System###Z
For a project that targets x64, copy paste:
?mainCRTStartupStrArray##$$FYMHP$01EAPE$AAVString#System###Z
Somewhere around VS2017 the designer fails to open a new form with a cryptic error message. Workaround is to build the project first, use Build > Build.
Remove the #include "stdafx.h" and this works well for VS 2022. The form must be hand coded since the Form Designer support was removed starting with VS 2012.

Intillisense fails on undefined namespace in XAML on Visual Studio 2010

I must be brain dead. I have tried for six hours now (with Google) and can not solve this very very simple problem.
In Visual Studio 2010, I created a project. (right-click on solution, Add new project...).
Inside the new project, I created a new folder of name Helpers. To the folder I added a class for a converter.
Inside the project, I added a new XAML window (in WPF). The Target Framework is .Net Framework 4.0
Everything has been built (multiple times) without compilation errors. The platform target build for the project is X86.
The problem: Intellisense does not see the namespace for the class under the Helpers folder and so the Visual Designer fails. The namespace in the Helpers folder is:
Chaos.UI.Helpers
and trying to reference this namespace in the XAML like:
xmlns:converters="clr-namespace:Chaos.UI.Helpers"
ofcourse results in the dreaded:
Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace 'Chaos.UI.Helpers' that is not included in the assembly.
These are clean files in the same project. The only added code is in the converter class contained in the Chaos.UI.Helpers namespace.
How do I fix this? (I need the designer to work).
Anybody, Plz help
Try use assembly
xmlns:converters="clr-namespace:Chaos.UI.Helpers;assembly=Chaos.UI"

How do I create a C++/CLI Winforms app in VS2012?

I just installed Visual Studio 2012 express for Desktop. I can't see any place to create a GUI application with C++ ! Where is this "Windows Form Application" used to exists in Visual C++ 2010 ? Where are these drag and drop controls? I installed this because I got details telling this supports GUI intellisense (Visual C++: Unable to invoke method from another class)
It is an unsubtle hint that they want you to stop creating C++/CLI Winforms applications. The plumbing is still in place however, at least for VS2012 and VS2013. This might not be the case in a future one.
You can turn a CLR console application into a Winforms application with these steps:
Start with File + New + Project, CLR node, CLR Console Application
Project + Add New Item, UI node, Windows Form
Project + Properties, Linker, System, SubSystem = Windows
Project + Properties, Linker, Advanced, Entry Point = main
Change the pre-generated .cpp file to look like this:
#include "stdafx.h"
#include "MyForm.h"
namespace ConsoleApplication45 { // Change this!!
using namespace System;
using namespace System::Windows::Forms;
[STAThread]
int main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew MyForm());
return 0;
}
}
Note that you'll need to change the namespace name to your project name. Press F5 to test. You can design the form as normal once everything checks out.
NOTE, Visual Studio 2015 has a nasty static initialization order bug in the CRT that can cause the app to crash instantly with an AVE at startup if the project contains any native C++ code. As yet an unfixed bug, the somewhat inevitable hazard of having these project templates removed. A possible workaround is to change the Entry Point (4th bullet).
For a project that targets x86, copy paste this string:
?mainCRTStartupStrArray##$$FYMHP$01AP$AAVString#System###Z
For a project that targets x64, copy paste:
?mainCRTStartupStrArray##$$FYMHP$01EAPE$AAVString#System###Z
Somewhere around VS2017 the designer fails to open a new form with a cryptic error message. Workaround is to build the project first, use Build > Build.
Remove the #include "stdafx.h" and this works well for VS 2022. The form must be hand coded since the Form Designer support was removed starting with VS 2012.

Recover WinForms from dll

We think most of the source has been recovered through .NET Reflector. A utility which export the dll as C# source.
The only missing part is WinForms which is not included when .NET Reflector export the dll source.
Is there any way to get the WinForms recover from dll?
Thanks.
If it's not in the dll, you can't get it out :-)
But possible some class files are the forms you're searching for. Maybe you have to add a reference to System.Windows.Forms.dll to your project.
From Visual Studio 2005 on, Windows Forms classes are partial classes split into a Designer generated part (MyForm.designer.cs) and your actual implementation (MyForm.cs). You can see that in Explorer when you create a new Form from scratch.
In order to resolve your problem you would have to split up the class exported by Reflector the same way that Visual Studio does: Place the InitializeComponent() method and all control declarations into the MyForm.designer.cs file and the remaining code into the MyForm.cs file.

Where is the System.Windows.Forms.Integration namespace?

I can't seem to find it, trying to keyboard input in a wpf form spawned from a winforms form. Found this: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/442782b1-00a1-4e2e-9cc6-ae99b6699126/ But when I try to use it, VS2008 complains about not being able to find the System.Windows.Forms.Integration namespace. I couldn't find a reference in the add references.
The only thing I can think of it maybe because it was a VS2005 project ported to VS2008?
You'll need to add a reference to WindowsFormsIntegration. If you do a Add Reference in Visual Studio, it will be near the last DLL available in the .Net tab
On my machine it's located at
%ProgramFiles%\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll
Visual Studio filters the available namespaces according to the type of project you chose. If you need a namespace that is not listed, click the [Add...] button on the references tab of your project's properties. This will pop-up the Reference Manager window. Choose "Framework" from the list of Assemblies in the left-hand panel. This will display all the Microsoft provided namespaces. You will find WindowsFormsIntegration there.
Just came across the same problem.
While adding a reference to WindowsFormsIntegration.dll didn't work as this has no WF controls in it, I did find that adding a reference to System.Windows.Forms worked perfectly fine.
Use newer:
%ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\WindowsFormsIntegration.dll

Resources