0

I have some code base which has is calling the following:

SetHazardDataService();

namespace Analytics.Foo.DataServices
{
    class HDB:IDataService
    {
    }
}

With a member function declared in another class/file

using Analytics.Foo.DataServices

public void MyDataService()
{
   var DbDataSvc = new HDB();
}

originally, I see the same definition used elsewhere but with (no idea if that works):

protected void MyDataService()

I included the public method in my class

I'm now trying to recreate that functionality, but I get the following issue:

The type Analytics.Foo.DataServices.HDB' has no constructors defined

I'm not sure what the issue is - any suggestions for why this is the case. There is no constructor that I can see. Plus I'm not able to see the other code working/but it doesn't give the same issue.

disruptive
  • 5,687
  • 15
  • 71
  • 135
  • 2
    confused... is this a partial class? I don't see any class declaration around the `MyDataService()` method. – T McKeown Apr 17 '14 at 16:02
  • Please post a more complete version of the source code so we can understand what exactly you are asking. – ryanulit Apr 17 '14 at 16:05
  • Does it matter that `HDB` isn't marked public? I would try adding `public HDB() { }` as at least an empty constructor to see whether it clears up the "no constructors defined" error. – OnlineCop Apr 17 '14 at 16:11
  • Are you calling this from the same assembly? The only possible cause of this that I can think of is [*this question*](http://stackoverflow.com/questions/6958358/the-type-has-no-constructors-defined). As other people have said there will always be a default constructor, and if you declare a private constructor you will get a different error (HDB()' is inaccessible due to its protection level). – codewrite Apr 17 '14 at 19:39

1 Answers1

-1

You need to create a constructor to class HDB, like this:

namespace Analytics.Foo.DataServices
{
    class HDB:IDataService
    {
        public HDB()
        {

        }
    }
}
Only a Curious Mind
  • 2,807
  • 23
  • 39
  • 1
    This is incorrect, if there's no constructor specified, there will be an empty public parameterless one by default – Ben Aaronson Apr 17 '14 at 16:38