tags:

views:

74

answers:

4

I have some strange problem. I have a solution with the following structure

http://i33.tinypic.com/10fbzbq.jpg

As you can see when i wonna import the VDB.Common.RequestAndResponses it gives an error. The namespace of dat Class Library is VDB.Common.RequestAndResponses.

I am new in c# , so it could be that i forgot something stupid.

+2  A: 

I strongly suspect that Base.cs (the only C# file shown in the VDB.Common.RequestAndResponses project) doesn't actually declare a type in the VDB.Common.RequestAndResponses namespace - or that it only declares an internal (rather than public) type.

For example, note that the code you're creating is under the VDB.Client.Infrastructure project, but is only declaring a class in the Agatha namespace - not VDB.Client.Infrastructure.Agatha, which may be what you were intending. Do you have the same kind of thing in Base.cs, perhaps?

Without seeing the code in Base.cs, we can't see what's wrong though. If you could just post a snippet of that - just the namespace and class declaration - that would be helpful.

Note that although a class library has a default namespace, this isn't prepended to whatever the source file actually declares. In other words, in a library of Acme.Widgets, if you had a declaration of:

namespace Web
{
    public class Button {}
}

that would only declare the type Web.Button, not Acme.Widgets.Web.Button.

EDIT: The OP's "answer" confirms what I thought... basically it's not declaring a namespace at all. It should look like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Agatha.Common;

namespace VDB.Common.RequestAndResponses
{
    public abstract class BaseRequest :Request
    {
        // Code
    }

    public abstract class BaseResponse : Response
    {
        // Code
    }
}

I would also strongly advise that these classes should be put in two separate files, BaseRequest.cs and BaseResponse.cs. I'm also pretty surprised to see a reference to Agatha.Common - shouldn't that be VDB.Common.Agatha or something like that?

Jon Skeet
+1 Pretty much as good an answer as can be inferred from the question
Peter Kelly
A: 

Right click on the "VDB.Common.RequestAndResponses" reference in solution explorer and choose "Show in object browser", make sure the namespace is found there with the exact spelling and capitalization.

Albin Sunnanbo
A: 
Peter Kelly
A: 

The Base.cs file looks like this.

using System;

    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Agatha.Common;

    public abstract class BaseRequest :Request
        {
        public string UserName { get; set; }
        public string UserDomainName { get; set; }

        public string ClientLanguageCode { get; set; }
        public DateTime ClientCreated { get; set; }
        public DateTime ClientSent { get; set; }
        public DateTime ServerReceived { get; set; }
        public DateTime ServerProcessed { get; set; }

        public void BeforeSend(IUserContext context)
        {
            ClientSent = DateTime.UtcNow;
            UserName = context.UserName;
            UserDomainName = context.UserDomainName;
            ClientLanguageCode = context.LanguageCode;
        } 
    }

public abstract class BaseResponse : Response
{
    public DateTime ServerCreated { get; set; }
    public DateTime ServerProcessed { get; set; }

    public string[] ValidationErrors { get; set; }

    public bool IsValid
    {
        get { return Exception == null & !ValidationErrors.Any(); }
    }

}
SvenVdb
@SvenVdb: This should have been an edit to the question, but it basically confirms what I thought. This isn't declaring a namespace at all, so it's in the "root" namespace. You should have "namespace VDB.Common.RequestAndResponses" around the whole thing.
Jon Skeet