Copied to clipboard

Flag this post as spam?

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

  • Igor 3 posts 73 karma points
    Feb 14, 2020 @ 07:00

    Nullreference exception IComponent IMacroRenderer

    Hello i have a problem..

    my code

    Initialize TaskExecuting

    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public class SubscribeComposer : IUserComposer {
        public void Compose(Composition composition) {

    TaskExecuting class

    public class TaskExecutingComponent : IComponent
        public TaskExecutingComponent(IProfilingLogger logger, IMacroRenderer macroRenderer, IUmbracoDatabaseService dataBaseService, IScopeProvider scopeProvider, UmbracoMapper umbracoMapper, SubscribeConfiguration config, IMacroService macroService, IPublishedSnapshotAccessor publishedSnapshotAccessor) {
        public void Initialize() {
            int delayBeforeWeStart = 60000;
            int howOftenWeRepeat = 60000; 
            var task = new Task(_sharePriceRunnerRunner,
        public void Terminate()

    And with problem moment

    public class Task : RecurringTaskBase {
        public Task(IBackgroundTaskRunner<RecurringTaskBase> runner, int delayBeforeWeStart, int howOftenWeRepeat, IProfilingLogger logger, IUmbracoDatabaseService dataBaseService, IScopeProvider scopeProvider, IMacroRenderer macroRenderer, UmbracoMapper umbracoMapper, SubscribeConfiguration config, IMacroService macroService, IPublishedSnapshotAccessor publishedSnapshotAccessor)
            : base(runner, delayBeforeWeStart, howOftenWeRepeat) {
        public override bool PerformRun() {
                var PageId = 999; // This page is present
            var macro = _macroService.GetById(task.MacrosId);
            var macro_params = _umbracoMapper.Map<IEnumerable<MacroParameter>>(macro);
            var maxro_param_val = new Dictionary<string, object>();
        maxro_param_val.Add("getFrom", DateTime.Now.Date());
            var content_val = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(PageId);
            var macro_props = maxro_param_val.ToDictionary(
                x => x.Key,
                i => i.Value is string ? HttpUtility.HtmlDecode(i.Value.ToString()) : i.Value);
            var result = _macroRenderer.Render(macro.Alias, content_val, macro_props).GetAsText();
            return true;

    And Exception

    in _publishedSnapshotAccessor.PublishedSnapshot.Content.GetById(_config.SubscribeMessage.SubscribePageId.Value);

    if i use other methods for recive Content i have problem with content in _macroRenderer.Render

  • Igor 3 posts 73 karma points
    Feb 16, 2020 @ 06:08

    I solved my problem, now I have a new problem)

    Solved how render macro in background task

    first im use

    (...,IUmbracoContextFactory umbracoContextFactory)

    when redid standard methods

    using (var umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext()) {
    var content = umbracoContextReference.UmbracoContext.Content.GetById(999);
    using (var controller = new MyPartialViewMacroController(macro_model, content)) {
        var route_vals = new RouteData();
        route_vals.Values.Add("controller", "PartialViewMacro");
        route_vals.Values.Add("action", "Index");
        //routeVals.DataTokens.Add(Core.UmbracoContextDataToken, umbCtx); //required for UmbracoViewPage
        if (umbracoContextReference.UmbracoContext.HttpContext == null)
            throw new NullReferenceException("HttpContext is null");
        var request = new RequestContext(umbracoContextReference.UmbracoContext.HttpContext, route_vals);
        //controller.ViewData = viewContext.ViewData;
        controller.ControllerContext = new ControllerContext(request, controller);
        //call the action to render
        result = controller.RenderViewResultAsString(controller.Index());


    Ok and incapsulate umbraco class PartialViewMacroController and rename to MyPartialViewMacroController


    Ok now i have problem in cshtml....

    var startnode = Umbraco.Content(startnode_id);

    DynamicMethod(Object[] )
    Umbraco.Core.FactoryExtensions.GetInstance[T](IFactory factory)
    Umbraco.Web.Runtime.WebInitialComposer.<>c.<C ompose>b__0_6(IFactory factory)
    Umbraco.Core.FactoryExtensions.GetInstance[T](IFactory factory)
  • Igor 3 posts 73 karma points
    Feb 16, 2020 @ 12:28

    Ok i solved all my probmels ....

    in schtml need use it for



Please Sign in or register to post replies

Write your reply to: