0

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.

1
  • Your file is not saved, do you think that might be the problem? Commented Aug 22, 2010 at 20:14

4 Answers 4

2

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?

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

1 Comment

+1 Pretty much as good an answer as can be inferred from the question
0

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.

Comments

0

Try to use the Base class in the client code and hover over it and allow the Visual Studio IDE to prompt you to add the appropriate namespace. The namespace defined in the Base class could be different to what you think.

EDIT As Jon as demonstrated in the 2nd part of his answer - the name of the code file does not automatically correspond to the namespace.

Comments

0

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(); }
    }

}

1 Comment

@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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.