Does source code make sense?

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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tguillorAuthor Commented:
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 :-)
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.