Resharper confused by ASP.NET 2.0 Web site projects

As the screenshot shows, Resharper finds error after error in my ASP.NET 2.0 projects. This has been a major annoyance, but I just figured out the true root cause.

By default, VS.NET 2005 and ASP.NET 2.0 create each new web page as a class named "_Default" in the global namespace. Look at the screenshot to see that there is no namespace specified. Also, because Default is a partial class, Resharper marks my base class as redundant with "Base type 'TestSweetPage' is already specified in other parts". Where I have an event handler in one page (in a class named "Default" in "TestResults.aspx") with the same name as an event handler in another page, "Go to declaration" asks me to choose between the two event handlers in different pages. Resharper thinks these are the same class.

In summary, because VS.NET 2005 and the ASP.NET 2.0 Web Site project template creates each page as a partial class named "_Default" in the global namespace, Resharper code analysis treats all these page classes as though they are all the same class. Because this is the default for VS.NET 2005, would JetBrains consider fixing this behavior?

Attachment not added (general error): "screen1.jpg"

12 comments
Comment actions Permalink

Resharper thinks these are the same class.


Yes, this is definately the case. I just did an F2 rename on the page shown
in the screenshot and renamed the class to "MaintainCasesPage". Now *.aspx.cs
in my project is named "MaintainCasesPage" and every *.aspx inherits from
"MaintainCasesPage".

Since this is so blatantly obvious and makes a certain kind of sense, in
a bizarro Mr. Spock kind of way, I'm thinking this issue must have been fixed
in an interim build. I'm using build #327. Did I miss one?


0
Comment actions Permalink

Any thoughts on this? I really think I'm on to something.


0
Comment actions Permalink

Hello flipdoubt,

Don't accept the name VS offers for Web Forms. Aways provide your own name.
Unlike Windows Forms apps, MS places the other part of the partial class
into a folder somewhere within the %windir% folder, I can't recall off the
top of my head where.

Also, unlike Windows Forms apps, renaming the file does not rename the class
associated with the Web Form, another reason to have a name ready when adding
a new Web Form.

If you organize you site with folders, when you add Web Forms to these folders,
the name you provide will be appended to the folder name to form the class
name. i.e. folder 'Reports' added Web Form 'Orders.aspx' creates class name
of 'Reports_Orders'.

If you follow these simple rules you will not have as many issues with R#.

Hope this helps.

As the screenshot shows, Resharper finds error after error in my
ASP.NET 2.0 projects. This has been a major annoyance, but I just
figured out the true root cause.

By default, VS.NET 2005 and ASP.NET 2.0 create each new web page as a
class named "_Default" in the global namespace. Look at the screenshot
to see that there is no namespace specified. Also, because _Default is
a partial class, Resharper marks my base class as redundant with "Base
type 'TestSweetPage' is already specified in other parts". Where I
have an event handler in one page (in a class named "_Default" in
"TestResults.aspx") with the same name as an event handler in another
page, "Go to declaration" asks me to choose between the two event
handlers in different pages. Resharper thinks these are the same
class.

In summary, because VS.NET 2005 and the ASP.NET 2.0 Web Site project
template creates each page as a partial class named "_Default" in the
global namespace, Resharper code analysis treats all these page
classes as though they are all the same class. Because this is the
default for VS.NET 2005, would JetBrains consider fixing this
behavior?



0
Comment actions Permalink

If you follow these simple rules you will not have as many issues with
R#.


Do you think the Resharper folks know about this issue and simply can't fix
it? Hrmph.

Your suggestion makes sense, but it still seems like a problem JetBrains
should fix because this is the default behavior for VS.NET. Also, the "Add
WebForm" wizard (though I usually right-click my MasterPage and select "Add
content form") does not give you a chance to name the class, just the file.
So we have to hand edit the *.aspx and *.aspx.cs to get it to work with Resharper.

That's what I'll do going forward, but I still can't shake the feeling that
JetBrains should fix the problem. Perhaps Resharper should give you an option
to rename the page class when it is created.


0
Comment actions Permalink

Hello flipdoubt,

I still think this is probably a MS issue. Prior to VS 2005, Web Forms had
namespaces and partial classes didn't exist. I don't know what they were
thinking about when they removed namespaces from the Web Forms, but it is
wrong to my thinking. I've never used "Add content form" from MasterPage
because when you add a new Web Form you are given the chance to select a
master page to bind to, but that's just my methodology, I guess.

>> If you follow these simple rules you will not have as many issues
>> with R#.
>>

Do you think the Resharper folks know about this issue and simply
can't fix it? Hrmph.

Your suggestion makes sense, but it still seems like a problem
JetBrains should fix because this is the default behavior for VS.NET.
Also, the "Add WebForm" wizard (though I usually right-click my
MasterPage and select "Add content form") does not give you a chance
to name the class, just the file. So we have to hand edit the *.aspx
and *.aspx.cs to get it to work with Resharper.

That's what I'll do going forward, but I still can't shake the feeling
that JetBrains should fix the problem. Perhaps Resharper should give
you an option to rename the page class when it is created.



0
Comment actions Permalink

Hello flipdoubt,

Ow, I just looked at 'Add content page'. I do not like that at all!

>> If you follow these simple rules you will not have as many issues
>> with R#.
>>

Do you think the Resharper folks know about this issue and simply
can't fix it? Hrmph.

Your suggestion makes sense, but it still seems like a problem
JetBrains should fix because this is the default behavior for VS.NET.
Also, the "Add WebForm" wizard (though I usually right-click my
MasterPage and select "Add content form") does not give you a chance
to name the class, just the file. So we have to hand edit the *.aspx
and *.aspx.cs to get it to work with Resharper.

That's what I'll do going forward, but I still can't shake the feeling
that JetBrains should fix the problem. Perhaps Resharper should give
you an option to rename the page class when it is created.



0
Comment actions Permalink

Ow, I just looked at 'Add content page'. I do not like that at all!

Hmmm, which do you use and why is it better? Maybe I'm not looking at the
right option?


0
Comment actions Permalink

Hello flipdoubt,

right-click project or subfolder in the project and select 'Add New Item'.
Select Web Form; change the name (you can leave off .aspx and it will be
added for you); select whether or not to select a master page to bind to;
and select whether or not to place code in a separate file.

This is preferable to 'Add content page' because when you organise your site
by function into separate folders then your master page(s) can be at the
root level or a separate folder. Additionaly, the class name associated to
folder segregated web form are automatically assigned unique names i.e. folder
name=Reports web form name = default.aspx (default page for this level) class
name= Reports_default so to access the page http://localhost/Reports/default.aspx.
If you add another web form named Orders.aspx to the Reports folder the class
would be Reports_Orders and page access http://localhost/reports/orders.aspx.


The short answer is each page has a unique class name and R# does not get
confused by all the different files with the same partial class. Additionally,
I feel you may be introducing some unexpected and undesireable side effects
with all the duplicate same-name partial classes.

>> Ow, I just looked at 'Add content page'. I do not like that at all!
>>

Hmmm, which do you use and why is it better? Maybe I'm not looking at
the right option?



0
Comment actions Permalink

I see. That way does work much better.


0
Comment actions Permalink

Hello Matt,

in 3.0 version of ReSharper we'll fix the problem with folder-based organization
of Web Sites. The root of the problem
is that VS puts every folder in a Web Site into a separate assembly, so there
is really no any naming clashes that confuse
ReSharper and make it think about different parts of the same class. We're
going to support this folder structure by considering
each Web Site folder a separate project internally.


Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


Hello flipdoubt,

right-click project or subfolder in the project and select 'Add New
Item'. Select Web Form; change the name (you can leave off .aspx and
it will be added for you); select whether or not to select a master
page to bind to; and select whether or not to place code in a separate
file.

This is preferable to 'Add content page' because when you organise
your site by function into separate folders then your master page(s)
can be at the root level or a separate folder. Additionaly, the class
name associated to folder segregated web form are automatically
assigned unique names i.e. folder name=Reports web form name =
default.aspx (default page for this level) class name= Reports_default
so to access the page http://localhost/Reports/default.aspx. If you
add another web form named Orders.aspx to the Reports folder the class
would be Reports_Orders and page access
http://localhost/reports/orders.aspx.

The short answer is each page has a unique class name and R# does not
get confused by all the different files with the same partial class.
Additionally, I feel you may be introducing some unexpected and
undesireable side effects with all the duplicate same-name partial
classes.

>>> Ow, I just looked at 'Add content page'. I do not like that at all!
>>>
>> Hmmm, which do you use and why is it better? Maybe I'm not looking at
>> the right option?
>>


0
Comment actions Permalink

The root of the problem
is that VS puts every folder in a Web Site into a separate assembly,
so there
is really no any naming clashes that confuse
ReSharper and make it think about different parts of the same class.


But Resharper certainly behaves as though it thinks the different pages are
part of the same class if renaming one page renames all pages in the project,
no?


0
Comment actions Permalink

Hello flipdoubt,

yes, at least I suppose so. And that's because ReSharper thinks that all
the pages are in the same single project and consider (actually) different
classes the
parts of the same class.


Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"



>> The root of the problem
>> is that VS puts every folder in a Web Site into a separate assembly,
>> so there
>> is really no any naming clashes that confuse
>> ReSharper and make it think about different parts of the same class.

But Resharper certainly behaves as though it thinks the different
pages are part of the same class if renaming one page renames all
pages in the project, no?



0

Please sign in to leave a comment.