Click here to Skip to main content
15,881,833 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi guys!
I have a huge problem to face. I have a C# project (called FP.Forms) which is a 'forms' library for my application and the other project containing controls (called FP.Controls). First of them has the default namespace set to FP.Forms, the other one to FP.Controls
FP.Controls library is added as a reference in FP.Forms.

The big problem is code generation done by windows forms designer... The generated code does not compile. Here's where the problem exists:

this.MainPanel = new System.Windows.Forms.Panel();
this.gearboxMainPanel1 = new FP.Controls.NicePanel();



The C# compiler throws the following error: error CS0234: The type or namespace name 'Controls' does not exist in the namespace 'FP.Forms.FP' (are you missing an assembly reference?)

What I've found is the compiler somehow adds at compile time the default namespace of the project (which is FP.Forms) to the code... so the compiler "tries to compile" the following line:

this.gearboxMainPanel1 = new FP.Forms.FP.Controls.NicePanel()


If so... why the hell it does not throw error on the
C#
new System.Windows.Forms.Panel();

??

The problem can be walked around by adding global:: before each namespace, but since the whole code is generated, the walkaround will be erased after any change is done to the form using a windows forms designer.
Have you guys have any idea what is going on?
Thanx in advance!
Posted

1 solution

First, the compilation of the project. The project does not consist of the source files along. Another important part is project file which provides the set of references assemblies.

Further issues depend on how you compile the code.

I would recommend you performing compilation from CodeDOM. Referenced assemblies are passed as an array of strings as a parameters to the constructor of CompilerParameters.
See this code sample on the compilation:
http://msdn.microsoft.com/en-us/library/system.codedom.compiler.codedomprovider.aspx[^].

So, this should clear your "compiler somehow adds at compile time". There is not "somehow", it's totally clear.

Now, how about compile-time error in one case not not showing error in another case? Simple.

This requires referencing of the assembly System.Windows.Forms:

C#
var something = new System.Windows.Forms.Panel();


Apparently, if there is no error, this assembly is references.
This is completely different:
C#
this.gearboxMainPanel1 = new FP.Forms.FP.Controls.NicePanel();


If requires some other assembly, the one you develop. You need to reference it, isn't that obvious?

Problem solved.

—SA
 
Share this answer
 
v3
Comments
HimanshuJoshi 18-May-11 19:49pm    
Your formatting was screwed, I fixed it.
Sergey Alexandrovich Kryukov 18-May-11 21:30pm    
Thank you very much. I fail to see the difference though... where?
--SA
HimanshuJoshi 18-May-11 21:38pm    
If you see the first revision of your post; the text after "This requires referencing of the assembly" was all red.
Sergey Alexandrovich Kryukov 18-May-11 22:45pm    
That's the thing I don't see it in that version, but thank you very much anyway.
--SA
morpheusss87 23-May-11 13:22pm    
Didn't I state clearly in my question that FP.Controls is added as a reference in FP.Forms?
Unfortunately the problem is not solved by your answer.

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