Question

I have created a C# Class Library. In it I insert two classes. For example:

Apple.cs Orange.cs

namespace FoodLibrary
{
 namespace Apples
 {
    public class Apples
    {
        public string type { get; set; }
        public string colour { get; set; }
        public string size { get; set; }
    }
 }
}

Almost an exactly identical one is formed for Orange.cs (The namespace Apples and class Apples would be turned into "Orange").

EDIT (Here is the requested Orange.cs):

namespace FoodLibrary
{
    namespace Orange
    {
        class Orange
        {
          public string colour { get; set; }
          public string type { get; set; }
          public string size { get; set; }
        }
    }
}

After building/rebuilding any combination I will get a .dll in the debug folder. Upon referencing this DLL it appears that I only have access to ONE namespace/class (ie. Apple). It allows me access to the first class I create in my Class Library. It doesn't matter how many classes I make, I only get one in my DLL.

I have had the same results in:

Visual Studios 2010 Visual Studios Express 2008 (C#)

Side Note: If I update the one class that works (ie. add a new property) it will change the DLL when I build. I have tried "clear","rebuild", and "build".

EDIT: Evidently I'm an idiot and didn't realize the orange wasn't public. Once I changed it, it worked. Not really sure why the class generated by a new project is "public" but when adding a new class it isn't or vice versa.

Thanks for the suggestions everyone.

Was it helpful?

Solution

Your Orange class is not declared as public like your Apples class is. Try declaring Orange as public - you should be able to access it then.

OTHER TIPS

In Visual Studio, select the Orange.cs file in the Solution Explorer, and look at the Properties pane. Is the Build Actions set to Compile? If not, the file isn't being included as source code.

Visual Studio, for some odd reason, sometimes changes the build action to something else when I create a new file. Check this guy's blog for a screenshot and similar problem.

http://dimarzionist.wordpress.com/2008/07/24/strange-vs-2008resharper-behaviour-buildaction-property/

  1. Keep your namespace names different to your class names ie namespace = AppleS class = Apple
  2. Change namespace ClassLibraryTest to FoodLibrary
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top