Does source code make sense?

Posted on 2006-06-23
Last Modified: 2010-04-16
I was given the task of "fixing" a C# Windows application.  The application runs in our shop, but the source code is kept at our headquarters, in a land far, far away.  In a lapse of propriety, I'll say that their source control is atrocious.  Most of the time, they can't find source code, much less know if it's current.  

For background info, they used an earlier version of C#.  The Framework is (can't remember exactly which).  We are using VS2005, Framework is 2.

When I opened the solution, it asked me if I wanted to upgrade.  I said yes.  So far, all appeared normal.  When I tried to build the resulting solution, I had 32 errors.  I resolved all but one of them in short order, by adding using statements and relatively easy things like that.

The last error, and the one that I saved for Monday, is detailed below.  I'm afraid my C# skills are not yet good enough to know if this is allowed.

The last error says that (we'll call it) ReportBuilder is declared twice in the same namespace.  There is a public class named ReportBuilder and a public method in that class named ReportBuilder.  Is that legal?  What's the answer to that?

But the more important question is, do you think this source code is what we are actually using in our compiled app?  Would the conversion from an older C# version to the latest version cause so many namespace errors?  I mean, these were .NET Framework namespaces, like System.Data, routine stuff like that.  Would the conversion process cause 31 of these things to be lost?

I know you can only speculate without seeing the code, but it sure makes me uneasy to have code that doesn't compile, and most of it for fairly trivial reasons.

Please give me your opinions.
Question by:tguillor
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

mistaeverly earned 500 total points
ID: 16973929
First off, it is valid (and in fact necessary) to have an identically-named function within a class.  This is the "constructor" and will get executed when the class is instantiated.  A simple example is:

public class ReportBuilder
  int id;
  public ReportBuilder()

In this case, when a new instance of the class is created (with code similar to "ReportBuilder myReportBuilder = new ReportBuilder()") the instantiated class will be inialized to have the id=-1.

As for ReportBuilder being declare in two places, my guess would be one of the three following possibilities:
1) Pre-Conversion, ReportBuilder existed within a namespace.  The "namespace" tags surrounding the class definition were removed and the name of the class matches a .NET pre-existing class, resulting in the overlap.
2) Post-Conversion, your page includes a "using" statement that didn't exist pre-conversion and this referenced namespace contains a class definition with the same name as your created class (what we're calling "ReportBuilder")
3) In 2.0. there is such a thing as a "partial" class.  When the "partial" keyword is used, it's a way of telling the compiler to merge the multiple class definitions into one class definition like follows:

public partial class Class1
 int a;

public partial class Class1
 int b;

In this case, the compiler merges these to get the following definitions:
public class Class1
 int a;
 int b;

So, if the "partial" keyword were removed post-conversion (if the conversion process introduced the them), the compiler would see it as two different classes with conflicting names rather than two parts of the same class.

With the "using" statements being lost, it is possible that the conversion process just placed the default using statements in the class definitions rather than what the old code was.  Personally, I haven't had much luck converting 1.1 Apps to 2.0 and I usually end up doing it manually so I'm not entirely sure how it works.

I hope this is of some help.  Including some applicable code could certainly help to diagnose the error more specifically.
Let me know if I can be of any more help.


Author Comment

ID: 16976448
Excellent answer, and very good info, Chad!!!  I will dig around in the code Monday and try to see why the compiler is complaining about "ReportBuilder".

Pretty intricate stuff the guy wrote, Web Services, delegates, he was really using what he learned in school :-)  And not the first comment anywhere in his code.  Last time I inherited some of his code, once I understood the business reason, I replaced a huge bloated app with eight lines of VBScript that performed the same functionality.  Added bonus: it even worked :-)

Expert Comment

ID: 16981389
As an inheritor of countless Delphi scripts that still make very little sense to me, I can certainly understand where you're coming from.

Let me know if you still need any help after testing this on Monday.

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question