Problem with Form
Hello,
I've made an assembly which uses System.Windows.Forms.Form. I created is as a seperate project (add to solution).
When I want to open the document (Form), there appears the following error:
An error occured while trying to create an instance of System.Windows.Forms.Form. The exception was "?"
Has anyone of you an idea how I could fix that problem?
Thanks!
Sebastian
[433 byte] By [
skuehner] at [2007-11-19 14:32:55]

# 1 Re: Problem with Form
Hi...
Maybe I should tell you, that I created the project like this:
1.) File -> New -> Project --> Class Library (add to solution)
2.) Click on project
3.) Project --> Add Windows Form
4.) Delete class1
5.) Add Interface to Form-Class
Is there any problem with this?
# 2 Re: Problem with Form
Maybe you can try to create the solution again. After you create a new class library, add the form file to the project.
If this still doesn't work, try to copy-paste the contents of the cs file into the already-there class file of the class library.
If this still doesn't work, maybe you can attach the entire solution to your post, so we can see if it happens in our computer also.
# 3 Re: Problem with Form
Now I created a new Project and added a Windows Form... and the Interface.
Now, LoadAssembly can't load it. It doesn't sound very logically to me. Is it a bug of .net?
In the "class-view" of the newer solution I see the Interface with a "+" (under bases and interfaces)... in the older one not.
I've the version 7.1
Thanks
P.D.: I'm new here... hoping that you answer that kind of questions
# 4 Re: Problem with Form
Thanks for your help...
I copied the whole code of the old project to the newer one (copy-paste) and changed only the class names.
I have the same problem: In the older solution I can't edit the form and I'm unable to assembly.GetType() the newer one...
(In the attachment the copy-paste-version)
# 5 Re: Problem with Form
Now I have two files with the same code... why do they have different "actitudes"? I don't understand that.
I had a look at the resx-file. The old solution doesn't have data in there... :-S ... this is really strange. I don't understand this
# 6 Re: Problem with Form
Class libraries don't usually have the System.Windows.Forms assembly attached as a reference. You have to add it manually by right clicking on references and selecting the System.Windows.Forms namespace from the .NET list.
This might be your problem.
Darwen.
# 7 Re: Problem with Form
Thanks!
When I add a Windows Form to the class-library-project, the references are added automatically (also System.Windows.Forms). That wasn't the problem.
Now I'm trying something else:
I make a empty class-library-project and I apply my interface to the class1. Then I make a new Form Class in the same project. The assembly is loaded correctly after that (LoadAssembly and GetType()). But when I want to connect class1 with Form1, the GetType of the assembly doesn't work anymore.
Does anyone understand that?
Here's my implementation:
public class TestDeviceForm2 : IDevice
{
string deviceName;
Form form;
public TestDeviceForm2()
{
//
// TODO: Add constructor logic here
//
}
... and the form-class normally
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace MATC.Devices
{
/// <summary>
/// Summary description for Form.
/// </summary>
public class Form : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
When I comment <<<Form form;>>>> in the first code, GetType() of the assembly works
... and when I make it in a Function, the assembly.gettype() does not make any trouble, but if I want to start the form:
public void Connect()
{
// TODO: Add TestDeviceForm2.Connect implementation
FormX formx;
//form = new FormX();
//form.ShowDialog();
}
there appears the following error:
An exception occurred while trying to create an instance of System.Windows.Forms.Form. The exception was "Unable to load DLL (AGL).".
Did I forget something? Is there any rule if you wants to create Forms a little bit more flexible than .net is used to manage it?
# 8 Re: Problem with Form
How do I create a Form in an assembly?
e.g.: I'm using all this on Windows CE