Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Amr Younis 13 posts 94 karma points
    Oct 18, 2016 @ 17:26
    Amr Younis
    0

    object reference not set to an instance of an object

    Hi Tim

    i'm sorry for late i post you this error before but i found the problem but i cannot solved enter image description here

    this code below is the reason when register dependencies

            var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
            builder.RegisterType<Ta2healDbContext>().As<IUnitOfWork>().InstancePerReques();
            builder.RegisterType<SubjectService>().As<ISubjectService>().InstancePerLifetimeScope();
            builder.RegisterType<SectionService>().As<ISectionService>().InstancePerLifetimeScope();
            builder.RegisterType<LessonService>().As<ILessonService>().InstancePerLifetimeScope();
    
            // Set the dependency resolver to be Autofac.
            var container = builder.Build();
            var resolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = resolver;
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
    

    and this when i stop some code of register dependencies

    enter image description here

    it's work when i do this into register dependencies code

           var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
            builder.RegisterType<Ta2healDbContext>().As<IUnitOfWork>().InstancePerRequest();
    
            builder.RegisterType<SubjectService>().As<ISubjectService>().InstancePerLifetimeScope();
            builder.RegisterType<SectionService>().As<ISectionService>().InstancePerLifetimeScope();
            builder.RegisterType<LessonService>().As<ILessonService>().InstancePerLifetimeScope();
            // Set the dependency resolver to be Autofac.
            //var container = builder.Build();
            //var resolver = new AutofacWebApiDependencyResolver(container);
            //GlobalConfiguration.Configuration.DependencyResolver = resolver;
            //DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
    

    but code that i stopped make some problem to me so i ask you if you have any idea what can i do to solve this problem?

    thanks Amr

  • DonZalmrol 220 posts 833 karma points
    Oct 18, 2016 @ 17:58
    DonZalmrol
    0

    Hi Amr,

    I am having the same issue as you. Did you did an upgrade as well from V7.4.x to V7.5?

    Cheers,

    Laurens

  • Amr Younis 13 posts 94 karma points
    Oct 18, 2016 @ 18:18
    Amr Younis
    0

    Hi Laurens,

    about the version i already run V7.5x

  • DonZalmrol 220 posts 833 karma points
    Oct 18, 2016 @ 18:01
    DonZalmrol
    0

    Seems it's working for me again.

    I did a rebuild index & optimize index from the developer backend -> examine management.

    Perhaps this could help you as well?

  • Comment author was deleted

    Oct 18, 2016 @ 18:20

    Hmm not sure, haven 't used it in combo Autofac, if you send project and db to tim at nibble dot be I can give a go at debugging...

  • Comment author was deleted

    Oct 18, 2016 @ 18:32

    And it also happens with other packages I see, https://our.umbraco.org/forum/developing-packages/80623-object-reference-not-set-to-an-instance-of-an-object

    So not sure the error has to do with UI-O-Matic in that case

  • Comment author was deleted

    Oct 18, 2016 @ 18:35

    Have you followed docs for using IOC https://our.umbraco.org/documentation/reference/using-ioc ?

  • Comment author was deleted

    Oct 31, 2016 @ 15:39

    Ok seems this is due to autofac, you'll need to registed the UI-O-Matic tree controller, for details check the known issues doc, btw you'll need to do this for every third party tree

    http://uiomatic.readthedocs.io/en/stable/13.KnowIssues/

  • Amr Younis 13 posts 94 karma points
    Nov 06, 2016 @ 08:43
    Amr Younis
    0

    HI Tim

    Thank you i did this and it's work correctly

    var builder = new ContainerBuilder();

            //register all controllers found in this assembly
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(typeof(UmbracoApplication).Assembly);
    
            //add custom class to the container as Transient instance
            builder.RegisterType<Ta2healDbContext>().As<IUnitOfWork>().InstancePerRequest();
            builder.RegisterType<SubjectService>().As<ISubjectService>().InstancePerLifetimeScope();
            builder.RegisterType<SectionService>().As<ISectionService>().InstancePerLifetimeScope();
            builder.RegisterType<LessonService>().As<ILessonService>().InstancePerLifetimeScope();
            //register UIOMatic
            builder.RegisterApiControllers(typeof(UIOMatic.Trees.UIOMaticTreeController).Assembly);
            //register uContactor
            builder.RegisterApiControllers(typeof(uContactorApiController).Assembly);
    
    
            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
    
  • Comment author was deleted

    Nov 06, 2016 @ 09:11

    Awesome, thanks for confirming the fix!

Please Sign in or register to post replies

Write your reply to:

Draft