Search code examples
c#classdllcompilationbuilding

c# DLL only compiling with one class


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.


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.