5

In my application, I use the ScintillaNET DLL and have created a class called BufferedScintilla where I am inheriting the control and double buffering it. Nothing unusual, just the normal C# inheritance... Than, I modified my form's Designer.cs file and switched from using ScintillaNET.Scintilla() to BufferedScintilla().

The app loads and works fine as expected BUT Visual Studio 2013 designer fails to load, telling me that "Unable to cast object of type BufferedScintilla to type ScintillaNET.Scintilla. I tried everything, cleaned the solution and rebuild, rebuild only, debug, closing and restarting Visual Studio and even restarting the PC, but nothing helps at all... Visual Studio Designer refuses to let me design my form.

Again, the app runs FINE, and I am sure that the control on the form is the new BufferedScintilla, not ScintillaNET.Scintilla, because I can see the effects (it is double buffered, the custom graphics I am drawing over it do not flicker anymore), so I am 100% sure the app runs WITH the inherited component.

I am sure this is some kind of Visual Studio little flaw, so I am looking for a solution to have it let me design my app again.

EDIT: To clarify, the same thing happens in Visual Studio 2013 Update 1 and Visual Studio 2010 too. I checked the assembly, it is built as Any CPU, so there should be no problem with the Visual Studio designer...

EDIT: As it seems impossible to fix this (some kind of a bug), I am looking forwar to a way of replacing lines in the Designer.cs file automatically before building the project, and then after the project was built (or not). Is there any Visual Studio tool which will replace some text in the class automatically after pressing the Build button before the project is built, and after it has been built? I want to replace the constructor and declaration, so that at design time it is ScintillaNET.Scintilla, and at run time it is BufferedScintilla. Thanks!

Thanks in advance!

Vali

Valentin Radu
  • 629
  • 1
  • 11
  • 26
  • Something you might want to consider, visual studio is a 32 bit process. If you build any libraries which contain form components as 64 bit libraries, visual studio will not be able to load them and use them in the designer. Everything will compile just fine and you'll be able to reference the 64-bit libraries, just not use them in the designer. – R M Apr 09 '14 at 21:50
  • Yes, I considered that too. That's not the problem here unfortunately... – Valentin Radu Apr 24 '14 at 09:48

1 Answers1

3

I've run into a problem very similar to this, In my case the designer still uses the constructors and the loaded events that are setup for the controls and forms. In my case, i was using a variable that was never set during design time, so to go around this you would have to modify you're code to do something like this...

if(this.DesignMode)
{
    //DoSomething();
}
else
{
    //DoSomethingElse();
}
Mike Monge
  • 66
  • 2