3

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.

5
  • What is the code for the second class? Commented Mar 19, 2013 at 23:47
  • 2
    Can you post the code for Oranges.cs? Commented Mar 19, 2013 at 23:47
  • 1
    Why do you have an Apples namespace for the Apples class? Why not just have Apples and Oranges in FoodLibrary? Commented Mar 19, 2013 at 23:51
  • I have added said Orange.cs. Please keep in mind these are just examples of a dumbed down project. I have created this example (with Apples and Oranges) and both projects are producing this result. I simply used this one for ease of understanding. Commented Mar 20, 2013 at 0:13
  • 1
    @ReedCopsey they always say you can't compare apples and oranges, so they clearly don't belong in the same namespace! :) Commented Mar 20, 2013 at 0:21

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Wow I'm a moron. Thank you, I will be on my way now. I assumed creating a class made them public by default. I won't make that mistake again.
Why when creating a new project is the class public but when adding a new one, not?
@user2188733 There's a good discussion of why this happens in this question. This question gives you information on how to change this behaviour.
For anyone wondering, the default for a class is internal when no access modifier is specified.
0

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/

2 Comments

Unfortunately this is not the issue as both Class files have said property set to "Build".
It was worth a shot. :) I don't suppose you can take a screenshot with the Orange.cs file open? Someone else might see the problem and have a good answer.
0
  1. Keep your namespace names different to your class names ie namespace = AppleS class = Apple
  2. Change namespace ClassLibraryTest to FoodLibrary

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.