none
Errors in declaring a generic base type. RRS feed

  • Question

  • I have a generic base class that is defined as:

    public class HandleMessageBase<R, S> : IHandleMessage where R : MessageRequestBaseType, new() where S : MessageResponseBaseType, new()
        {
            private R _request;
            private S _response;
            private bool disposed;
            public HandleMessageBase(MessageRequestBaseType request)
            {
                this._request = (R)(request);
                this._response = new S();
            }
            public R Request
            {
                get
                {
                    return this._request;
                }
            }
            public S Response
            {
                get
                {
                    return this._response;
                }
                set
                {
                    this._response = value;
                }
            }
            public virtual void Dispose()
            {
                this.Dispose(true);
                GC.SuppressFinalize(this);
            }
            private void Dispose(bool disposing)
            {
                if (this.disposed != true)
                {
                    if (disposing)
                    {
                    }
                    this.disposed = true;
                }
            }
            public virtual void Init()
            {
            }
            public virtual void Init(Type[] testingImplementations)
            {
            }
            public virtual void Init(Type[] testingImplementations, IBsiDataConnection[] testingConnections)
            {
            }
            public virtual void Init(IBsiDataConnection[] testingConnections)
            {
            }
            public virtual void Init(IBsiDataConnection[] testingConnections, IBsiDataConnection[] defaultConnections)
            {
            }
            public virtual void Init(Type[] testingImplementations, IBsiDataConnection[] testingConnections, IBsiDataConnection[] defaultConnections)
            {
            }
            public virtual MessageResponseBaseType Execute()
            {
                return this._response;
            }
        }
    I get two errors in compiling this code. One:

    The namespace 'xxx.DataContracts' already contains a definition for 'HandleMessageBase'
    



    I have searched for HandleMessageBase in the whole solution and this name does not appear anywhere else. I am confused as to where it is already defined.

    Partial declarations of 'xxx.DataContracts.HandleMessageBase<R,S>' must have the same type parameter names in the same order
    I don't understand what this error is referring to or how to correct it.

    Thank you.


    Kevin

    Wednesday, May 27, 2009 5:09 PM

Answers

  • Well, that explains it.  I assume you need:

      public class MyHandler : HandleMessageBase<GetSiteConfigurationRequestType, GetSiteConfigurationResponseType> {
        // etc..
    }

    Hans Passant.
    • Marked as answer by KevinBurton Wednesday, May 27, 2009 5:49 PM
    Wednesday, May 27, 2009 5:48 PM
    Moderator

All replies

  • I assume the 2nd error is caused by the 1st one.  Maybe you've got the type defined in a referenced assembly?  View + Object Browser and use its Search feature.
    Hans Passant.
    Wednesday, May 27, 2009 5:16 PM
    Moderator
  • I don't see a duplicate definition in this namespace.
    Wednesday, May 27, 2009 5:21 PM
  • If it helps the first error seems to occur when I am actually declaring a generic type:

        public class HandleMessageBase<GetSiteConfigurationRequestType, GetSiteConfigurationResponseType>
        {
    



    Kevin
    Wednesday, May 27, 2009 5:29 PM
  • Well, that explains it.  I assume you need:

      public class MyHandler : HandleMessageBase<GetSiteConfigurationRequestType, GetSiteConfigurationResponseType> {
        // etc..
    }

    Hans Passant.
    • Marked as answer by KevinBurton Wednesday, May 27, 2009 5:49 PM
    Wednesday, May 27, 2009 5:48 PM
    Moderator
  • Duh. Thank  you.
    Wednesday, May 27, 2009 5:49 PM