Home Dashboard Directory Help

ASP .NET ControlBuilder Type Substitution not Respected in VS .Designer File by Cobalt Software



Sign in
to vote
Type: Bug
ID: 575898
Opened: 7/16/2010 1:07:47 PM
Access Restriction: Public
User(s) can reproduce this bug


Some changes to the way Visual Studio 2010 code generation is done for ASP .NET .designer.cs/vb files means that when using controlbuilder driven generics the .designer file is now writing out a declaration of the base/original type, not the generic type.

Example code for this issue can be found on my CodeProject article:


I've tried applying the fix required as per another change (to allow the controlbuilder itself to work):


However in the codebehind I get the non-generic control declared as a property, not the type that the control builder is dropping in. This means that any code that wishes to refer to the generic control requires the declaration to be removed from the .designer file and placed in the other code-behind file, and corrected to use the run-time type that will actually be present.

Sign in to post a comment.
Posted by Cobalt Software on 4/6/2011 at 8:33 AM
What is the nature of the problem? Is there *any* way to work around this so I can republish my tutorial? 2012 is a long way away. If it's just a case of me implementing an extra property or overriding some methods, fine. I'm trawling the code that generates the designer files with reflector trying to understand what's going on.
Posted by Microsoft on 4/5/2011 at 12:37 PM
This bug only applies to web application projects.
Posted by shanina on 4/4/2011 at 3:41 AM
Is this for a web application or a web site? It doesn't seem to be working on a web site,
the declaration still appears in the ASP.NET temp directory.
Posted by Microsoft on 3/31/2011 at 10:44 AM
After you add the declaration to Page.aspx.cs save the file.
Close and re-open Page.aspx.
Make a change to Page.aspx and save it.
Now look in the Page.aspx.designer.cs.
It should no longer have a duplicate declaration for the control id.
That will fix the compilation error and it should never come back.
Posted by shanina on 3/17/2011 at 12:17 AM
I Tried declaring a variable in the Page.aspx.cs file of the Page.aspx like this:
protected GenRepeater<SomeType> segmenter;

And I Still get 'Type Expected errors' and a new one:
'Error    34    Ambiguity between 'Page.segmenter' and 'Page.segmenter'
Posted by Microsoft on 3/16/2011 at 1:22 PM
The fix is checked into the next major release (ie VS 2012 or whatever it gets called). The fix is not in a servicing branch of VS 2010.

Do not change the designer file (page.aspx.designer.cs). As you pointed out the change will get overwritten. You should create a declaration for the control in the corresponding codebehind file (page.aspx.cs). You can use whatever type you want in the declaration. Any changes to the page (page.aspx) will not change the delaration in the codebehind (page.aspx.cs). Also, a duplicate declaration will not be written into the auto-generated half of the partial class in the designer file (page.aspx.designer.cs).

Hope this helps.
Web Tools Team
Posted by Cobalt Software on 3/9/2011 at 7:52 AM
It's good to know it's been fixed. When you say next version, are you referring to an upcoming patch/hotfix for Visual Studio 2010, or are you talking about the 2012 iteration?

Is there any way I can work around this without having to manually go through projects one by one and replace these generated declarations manually - every time anyone touches a pages markup and the generated codebehind gets rebuilt the page suddenly breaks, and it's not very straighforward to see why.

I'd also like to resubmit my CodeProject tutorial with an updated VS 2010-enabled version of the code.
Posted by Microsoft on 3/8/2011 at 8:48 AM
To work around this problem in Visual Studio 2010 you can declare your control manually in the code behind file using the type specification you desire. Once present in the code behind file the declaration will not be auto-generated in the designer file.
Posted by Microsoft on 3/8/2011 at 8:46 AM
Sorry for the delay. Thanks again for the bug report. We have fixed the problem in the next version of Visual Studio.

Microsoft Web Platform and Tools Team
Posted by Cobalt Software on 12/31/2010 at 5:47 AM
Come on Microsoft? It's been nearly five months since I initially submitted this, and was told "expects will follow-up with your issue.". The change has broken quite a few examples/projects out there, some production code I'm using (I've kept the code 2008 until this can be resolved).
Posted by aspicer on 11/10/2010 at 7:05 AM
Here is a link to another example of the same problem which worked in VS 2008 but not in VS 2010.

Posted by n.harding on 10/21/2010 at 8:43 AM
Seconded - Need to convert a project to vs2010/.net 4.0 for RIA data services but can't build due to this
Posted by Cobalt Software on 8/28/2010 at 9:26 AM
It's been over a month? Is there any movement on this issue? I'm wondering if I need to give up on ASP .NET generics integration, which has served me somewhat well for the last few years.
Posted by Microsoft on 7/19/2010 at 2:44 AM
Thanks for your feedback. We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 7/16/2010 at 5:08 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.