Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Compile error when merging classes into a single namespace

  Asked By: Erica    Date: Dec 19    Category: Asp.net    Views: 1185
  

I've recently merged two classes from code-behind pages into a single
namespace definition (using c#). I then changed the page directives
in both of my aspx files to point to the same .cs file
(Src="default.aspx.cs") and both have their proper definitions to
their "working" class (Inherits="BB.BBList" and
Inherits="BB.BBSelectPage"). In my code behind, I have:


using ...
namespace BB
{
public class BBSelectPage : System.Web.UI.Page
{
...all its members...
}
public class BBList : System.Web.UI.Page
{
...all its members...
}
}

Because I use the Src page directive, the code behind compiles when I
load the aspx in IE - which works fine & the pages function. (I've
tested that it works ok by inserting/removing Response.Write text in
VS.net & reloaded the pages) The error I've been having though is
that when I try to build the BB namespace in VS.net - I get the
error "E:\archive\BB\default.aspx.cs(250): The namespace 'BB' already
contains a definition for 'BBList'"

I verified that there's only one definition of this class in the
current namespace - so I'm thinking that perhaps a previously built
dll with the old namespace definition exists - and is causing this
error.

Before I merged the 2 classes, I had two separate aspx pages pointing
to two separate code-behinds with similar namespace definitions:

+++ page1.aspx.cs +++
using ...
namespace BB
{
public class BBSelectPage : System.Web.UI.Page
{
...all its members...
}
}

+++ page2.aspx.cs +++
using ...
namespace BB
{
public class BBList : System.Web.UI.Page
{
...all its members...
}
}

The last page I've used/tested was page2.aspx. I've also checked
the /bin directory for the application & deleted the existing dll &
have restarted IIS (and VS.net) to make sure nothing was being
cached. I still get this error. Any ideas?

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Russell Burns     Answered On: Dec 19

try remove the src  or the inherits atribute from your @ directive.

you are definng the inherits of the web  form and then the runtime try to compile  the code  that exists  in src and then this happens.

i´m not sure but when using src atribute, you cant define inherits. you put it on @ directive  when your application  get published.

 
Answer #2    Answered By: Louis Mason     Answered On: Dec 19

are you mixing src  and code-behind  in same file? you sohuld not.....

 
Answer #3    Answered By: Hehet Chalthoum     Answered On: Dec 19

No.. I have my html src  in 2 .aspx files  & the 2 classes  handling
those pages  in one namespace in a single  .aspx.cs file...

 
Answer #4    Answered By: Sean Grant     Answered On: Dec 19

however I still am unable to compile  the code-behind  page. I tried the 4 following combinations: removing the Src & removing the Inherits tags from both aspx  directives, keeping the Src directives in both & removing the Inherits from both, removing the Src directives in both & keeping the Inhertis directives in both, and of course (the original scenario) having both Src & Inherits directives in both. I still get the error  "E:\archive\BB\default.aspx.cs(250): The namespace 'BB' already contains a definition  for 'BBList'" every time...

 
Answer #5    Answered By: Chad Bradley     Answered On: Dec 19

I just discovered a solution to my earlier problem - as a reference to
anyone else that might experience a similar issue:


When I first created these 2 pages  - each page  referred to its own .aspx.cs
file. After I made my changes (manually) to merge the two code-behinds
together - I made sure that there were no longer references in my aspx  files
to old aspx.cs files. Even though there weren't references in the code,
VS.Net still held a reference to the code-behind  page which I merged
(bblist.aspx.cs). In the Solution Explorer, I had to click "Show all files"
and then delete the file reference to that page -- afterwards then the
solution would build  just fine  in VS.

 
Didn't find what you were looking for? Find more on Compile error when merging classes into a single namespace Or get search suggestion and latest updates.




Tagged: