Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3351526
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:55:10+00:00 2026-05-18T01:55:10+00:00

I am getting System.StackOverflowException was unhandled on public VolunteerDBEntities() : base(name=VolunteerDBEntities, VolunteerDBEntities) { OnContextCreated();

  • 0

I am getting “System.StackOverflowException was unhandled” on public

VolunteerDBEntities() : base("name=VolunteerDBEntities", "VolunteerDBEntities")
        {
            OnContextCreated();
        }

It happens when I change this:

   public class OrganizationService : IOrganizationService
    {

        private IValidationDictionary _validationDictionary;
        private IOrganizationRepository _repository;

        public OrganizationService(IValidationDictionary validationDictionary)
            : this(validationDictionary, new OrganizationRepository())
        { }


        public OrganizationService(IValidationDictionary validationDictionary, IOrganizationRepository repository)
        {
            _validationDictionary = validationDictionary;
            _repository = repository;
        }
...}

To this:

public class OrganizationService : IOrganizationService
    {

        private IValidationDictionary _validationDictionary;
        private IOrganizationRepository _repository;
        private ISessionService _session;

        public OrganizationService(IValidationDictionary validationDictionary)
            : this(validationDictionary, new OrganizationRepository(), new SessionService())
        { }


        public OrganizationService(IValidationDictionary validationDictionary, IOrganizationRepository repository, ISessionService session)
        {
            _validationDictionary = validationDictionary;
            _repository = repository;
            _session = session;
        }
...}

I’m clueless on this one. I set this up for unit testing and anytime I add a class variable to this service, it crashes. I can add a class variable to another services or create a service that replicates this minus the interface and it works. Any ideas?

Session Service Construct:

   public class SessionService: ISessionService 
    {
        private IMembershipService _membershipService;
        private IVolunteerService _volunteerService;
        private IMessageService _messageService;

          public SessionService() 
            : this(new AccountMembershipService(null), new VolunteerService(null), new MessageService())
        {}


          public SessionService(IMembershipService membershipservice, IVolunteerService volunteerservice, IMessageService messageservice)
        {
            _membershipService = membershipservice;
            _volunteerService = volunteerservice;
            _messageService = messageservice;
        }

Other Service Constructs:

private IValidationDictionary _validationDictionary;
private IVolunteerRepository _repository;
private IOrganizationService _orgservice;

public VolunteerService(IValidationDictionary validationDictionary) 
    : this(validationDictionary, new VolunteerRepository(), new OrganizationService(null))
{}


public VolunteerService(IValidationDictionary validationDictionary, IVolunteerRepository repository, IOrganizationService orgservice)
{
    _validationDictionary = validationDictionary;
    _repository = repository;
    _orgservice = orgservice;

}



public class AccountMembershipService : IMembershipService
{
    private readonly System.Web.Security.MembershipProvider _provider;
    private IValidationDictionary _validationDictionary;
    private IVolunteerService _volservice;
    private IEmailService _emailservice;

    public AccountMembershipService(IValidationDictionary validationDictionary)
        : this(validationDictionary, null, new VolunteerService(null), new EmailService())
    {
    }

   public AccountMembershipService(IValidationDictionary validationDictionary, System.Web.Security.MembershipProvider provider, VolunteerService volservice, EmailService emailservice )
    {
        _validationDictionary = validationDictionary;
        _provider = provider ?? Membership.Provider;
       _volservice = volservice;
       _emailservice = emailservice;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:55:11+00:00Added an answer on May 18, 2026 at 1:55 am

    You are creating the set of objects recursively.

    Your code “smells” with test logic in production because you create all the objects implicitly.

    Instead I would encourage to use dependency injection or other solutions so that you do not have hard dependencies in your constructors.

    In the worst-case scenario, just use ServiceLocator pattern.

    The last option is the easiest way to go for you as you already have too much stuff bound together. Your code would look like this:

       public class OrganizationService : IOrganizationService
        {
    
            private IValidationDictionary _validationDictionary;
            private IOrganizationRepository _repository;
    
            public OrganizationService() {
                _validationDictionary = ServiceLocator.Get<IValidationDictionary>();
                _repository = ServiceLocator.Get<IOrganizationRepository>();
            }
        }
    

    Let’s look at the dependency on IOrganizationRepository here.

    We don’t need to know exact type of it. So we don’t care. The ServiceLocator is the only body that does care.

    Usually it is just a static class (keep in mind multi-threading and synchronization though!).

    It can be implemented like this (I don’t want to point to existing implementations because it is just too simple to do):

    public static class ServiceLocator {
        static Func<T, object> _resolver;
    
        public static Setup(Func<T, object> resolver) {
            _resolver = resolver;
        }
    
        public static TService Get<TService>() {
            if (_resolver == null) throw InvalidOperationException("Please Setup first.");
            return (TService)_resolver.Invoke(typeof(TService));
        }
    }
    

    Then in your test setup (probably on the base test class) just do this:

    ServiceLocator.Setup(what => {
        if (what == typeof(IOrganizationRepository))
            return organisationRepository = organisationRepository ?? new OrganizationRepository(); // Singleton
        throw new NotSupportedException("The service cannot be resolved: " + what.Name);
    });
    

    In production you would instantiate it differently.

    Of course it can be easier with CastleWindsor, Microsoft Unity or other dependency injection framework.

    Hope that will help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error System.Web.HttpException was unhandled by user code Message=Validation of viewstate
I'm getting a stackverflow error while executing InvokeRequired. System.StackOverflowException was unhandled How to fix
Error im getting: An unhandled exception of type 'System.StackOverflowException' occurred in System.Management.dll My callstack:
I am getting An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.dll in my
I used the SystemEnvironment class in Java for getting system information. In that I
We are getting this error: System.ServiceModel.ServerTooBusyException: The request to create a reliable session has
I am getting System.UnauthorizedAccessException was unhandled by user code when deleting user alerts by
After Getting a System.Reflection.PropertInfo array for a class- Does anyone know how or if
I’m getting system error when I try to compile the code below on Visual
I'm getting a System.NullReferenceException when my application starts up (after a small login screen)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.