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 6860587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:25:38+00:00 2026-05-27T02:25:38+00:00

I’m having problems resolving a repository when calling it from a console app. Everything

  • 0

I’m having problems resolving a repository when calling it from a console app. Everything works fine when running the application (.NET 4, C#, Entity Framework, Unity) as normal, but I’ve created a standalone console app that will be run from the task scheduler to import feeds. I’m very close to giving up and do a dirty hack and write a script to call a webpage instead of using a console app, but I thought I’d at least try to understand why it isn’t working first.

I’m new to both Entity Framework and Unity, so please bear with me and let me know if I’ve left out any important information.

This is the error I’m getting:

Resolution of the dependency failed, type = "MyNamespace.Domain.Template.IRepository`2[MyNamespace.Domain.Employees.OrganisationalUnit,System.Guid]", name = "(none)".
Exception occurred while: while resolving.
Exception is: NullReferenceException - Object reference not set to an instance of an object.

at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)
at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides)
at Microsoft.Practices.Unity.UnityContainerExtensions.Resolve[T](IUnityContainer container, ResolverOverride[] overrides)
at MyNamespace.Infrastructure.FeedDefinition.GetOrganisationalUnit(String name, OrganisationalUnit parent) in C:\FeedDefinition.cs:line 552

This is the console app code:

static void Main(string[] args)
{
    if (args.Length > 0)
    {
        MyNamespace.Appliance.Configuration.Initialise.InitialiseContainer();

        ImportFeedProcessor importFeedProcessor = new ImportFeedProcessor();

        importFeedProcessor.Run(args[0]);
    }
}

And this is where it fails:

IRepository<OrganisationalUnit, Guid> organisationalUnitRepository = 
    Context.Instance.Container.Resolve<IRepository<OrganisationalUnit, Guid>>();

If anyone can help me understand what’s going wrong I’d be very grateful!

UPDATE:

Here’s the (important) bits from the initialise class:

public static void InitialiseContainer()
{
    UnityContainer container = new UnityContainer();

    // Use HttpContext for registering instances against for live
    IContext context = HttpContextWrapper.Instance;

    // Register the HttpContext as the default context to use
    container.RegisterInstance<IContext>(HttpContextWrapper.Instance);

    // repositories
    container.RegisterType<IRepository<Employee, Guid>, EmployeeRepository>(
        new UnityContextLifetimeManager(context),
                new InjectionConstructor(true, "OrganisationalUnit.Parent.Parent"));
    container.RegisterType<IRepository<OrganisationalUnit, Guid>, EntityFrameworkRepository<OrganisationalUnit, Guid>>(
                new UnityContextLifetimeManager(context),
                new InjectionConstructor("Parent.Parent"));

    // Create and populate a new Unity container from configuration
    Context.Instance.Container = container;
}

Is it perhaps the HttpContext that does it?

Thanks,

Annelie

  • 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-27T02:25:38+00:00Added an answer on May 27, 2026 at 2:25 am

    One option you could consider is creating two different Initialise classes (I’m guessing that is your Unity bootstrapper class).

    The one you have can be used for your web application.

    The other one should be non-web specific. Remove any reference to HttpContext (it won’t be available in a Console app) and UnityContextLifetimeManager (assuming this is HttpContext specific as well).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.