3

I am developing a winforms application, and I want to place the designers into a separate project, because it requires the reference to .Net full framework (System.Design), while the application itself requires .Net framework client version only.

I have 3 projects:

  1. TestControls with TestUserControl
  2. TestControls.Designers with PanelHodelerDesigner
  3. TestApp to test the TestUserControl

TestControls and TestControlsDesigners are signed and registered in GAC.

When I define Designer for the user control as follows, VS cannot locate the designer

[Designer("TestControls.Designers.PanelHolderDesigner, TestControls.Designers")]
public partial class TestUserControl : UserControl, IPanelHolder
{
    ...
}

When I change it to fully qualified name including version, culture and publicKeyToken like follows, VS loads the designer correctly.

[Designer("TestControls.Designers.PanelHolderDesigner, TestControls.Designers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=520302431ebc763b")]
public partial class TestUserControl : UserControl, IPanelHolder
{
    ...
}

All samples in the web that I found teach that I should use shorten version. Why it does not work for me? What else should I do to use the short version of designer attribute?

xll
  • 3,019
  • 2
  • 16
  • 19

1 Answers1

4

Feature, not a bug. The GAC was designed to be able to store multiple versions of an assembly side-by-side. If you don't specify the [AsssemblyVersion] then the CLR doesn't stand a chance to guess at the correct one. So it doesn't try, it only looks in the probing path of the running app for the display name. These "samples" you found probably all assume that you don't use the GAC.

It is probably going to be difficult to talk you out of this, but separating the designer from the control isn't a great idea. Microsoft does this, but they are extraordinarily reluctant to ever change the [AssemblyVersion] of a .NET Framework assembly. And expend massive resources to ensure they never have to. That's is very hard to duplicate, versioning assemblies is rather important to mere mortals like us, we don't spend three or more years on designing and testing assemblies to ensure that the hundreds of thousands of programmers that use them don't run into trouble.

Short from having trouble on your own machine, getting this to still work correctly on another programmer's machine is hard enough in itself. I never hesitate to use typeof() in the [Designer] attribute and include the designer with the control. Never a surprise that way. That's a spit of IL that never gets loaded at runtime, taking advantage of the you-don't-pay-for-what-you-don't-use CLR behavior is hard to pass up when it solves icky problems like this.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • I am keeping it separate because designer needs full version of .Net framework. I don't want to require full framework for the clients. – xll Jul 31 '14 at 13:08
  • How can I avoid using GAC ? I don't want to register the libraries in GAC, but how the VS will find the designer then ? – xll Jul 31 '14 at 13:10
  • It will never have any trouble finding it if you use the recommendation I gave, the one after "It is probably going to be difficult to talk you out of this". You will when you keep it separate, it has to be deployed in a location where the CLR can find it. The GAC or one of the directories that VS searches for assemblies, like its PublicAssemblies subdirectory. You will not have trouble with assemblies that are not present in the Client Profile if the designer class never gets loaded. Assemblies are only ever loaded when needed. – Hans Passant Jul 31 '14 at 13:16