For Programmers: Free Programming Magazines  


Home > Archive > C# > January 2006 > Trouble with using User Control in different projects









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Trouble with using User Control in different projects
crowl@gmx.de

2006-01-24, 7:02 pm

VS.2003, .NET Framework 1.1, C#

My goal: Creating a dll (helper.dll) which contains some UserControls
and some other helpful classes in order to use it in other projects.

Symtoms: The inital use of the UserControl component works. However, if
the Helper Project is recompiled, the UserControl does not work
correctly anymore in the other projects. Furthermore, the previously
visible User Control may not be visible in the Windows Form Designer.

Here the steps I have done:

1) Created a new Project (Helper Project)
2) Added some classes and a UserControl (there are some textboxes,
dropdown boxes, etc.)

Remark: UserControl (ctlHelper.cs)
public class ctlHelper : System.Windows.Forms.UserControl

3) Compiled the procject.

Now the next steps are including the dll in the desire project.
1) Created a new Project
2) Added a new reference to the helper.dll
3) Add -> Add Inherited Control -> Inherited User Control -> Browse to
the helper.dll location -> OK
Now the designed UserControl appears in the Toolbox of VS.2003 under
"My User Controls"
4) Drag & Drop the UserControl to the windows form. Write some code,
compile.

This work so far.

But if I made any change in the helper project, compiling it (the
public interface of the helper.dll is untouched!) all Projects which
using the UserControl getting trouble. In all the projects the
UserControl is disappeared from "My User Controls", further, the
Windows Form Designer does not show the UserControl on the Windows Form
as where it was before. The ctlHelper.cs file is still part of the
project. The written code using the UserControl is there, too.
Compiling works too. But if I run the application the UserControl is
not shown in the Windows Form.

The problem is similar as described in KB 818220, but I am useing .NET
UserControl.
http://support.microsoft.com/?kbid=818220
Also the workaround works but it is unacceptable. This helper
repository should be used by several programmers in their projects. The
user control should gives consistency across all projects.

What to do in order to get this working?

Any help is appreciated. Thanks in advance.

cw

NuTcAsE

2006-01-26, 7:02 pm

First thing to check is if your user control's AssemblyInfo.cs file has
dynamic assembly versioning enabled (if [assembly:
AssemblyVersion("1.0.*")] is there then everytime you bild the control
project it updates the version no)

If the AssemblyVersion is dynamic (contains *) then everytime you build
your project it updates the version no of the assembly. Now since you
are using File References, the project you add your user control
library to expects an assembly with a different version no, which
causes the error. The example is illustrated below:


Lets say the control library project is ctlLib.dll. Initial version
after building it is 1.0.0.0. Now Project B references this library and
is bound to version 1.0.0.0. Lets say you build ctlLib again the now VS
updates the version of the dll to 1.0.0.1. Now project B can not locate
the file because the 1.0.0.0 version does not exist.

To overcome this problem set the versioning scheme used by the VS, i.e
remove * and set the assemblyVersion attribute to 1.0.0.0. This will
always build the assembly as 1.0.0.0, or use Project based references
in VS.

Hope this helps...
-NuTcAsE

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com