{"action":"closed","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/4918","repository_url":"https://api.github.com/repos/aspnet/Mvc","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/4918/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/4918/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/4918/events","html_url":"https://github.com/aspnet/Mvc/issues/4918","id":162742288,"number":4918,"title":"RC2 - @addTagHelper error ","user":{"login":"dazinator","id":3176632,"avatar_url":"https://avatars.githubusercontent.com/u/3176632?v=3","gravatar_id":"","url":"https://api.github.com/users/dazinator","html_url":"https://github.com/dazinator","followers_url":"https://api.github.com/users/dazinator/followers","following_url":"https://api.github.com/users/dazinator/following{/other_user}","gists_url":"https://api.github.com/users/dazinator/gists{/gist_id}","starred_url":"https://api.github.com/users/dazinator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dazinator/subscriptions","organizations_url":"https://api.github.com/users/dazinator/orgs","repos_url":"https://api.github.com/users/dazinator/repos","events_url":"https://api.github.com/users/dazinator/events{/privacy}","received_events_url":"https://api.github.com/users/dazinator/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-28T17:32:21Z","updated_at":"2016-06-28T18:48:59Z","closed_at":"2016-06-28T18:48:59Z","body":"There is an assembly containing an `ViewComponent`, and it's Razor files (embedded as resources)\r\nI load the assembly from disk:\r\n\r\n```\r\nvar assy = Assembly.Load(somePath);\r\n```\r\n\r\nI register it with MVC using `ApplicationParts`\r\n\r\n```\r\n\r\n var mvcBuilder = services.AddMvc();\r\n mvcBuilder.AddApplicationPart(assy);\r\n\r\n```\r\n\r\nThen I configure Razor, with an `EmbeddedFileProvider` so it can discover the Razor view, and it's `CompilationContext` so that it compile the Razor view with a reference added for the assembly itself (as that where it's model is):\r\n\r\n```\r\n            mvcBuilder = mvcBuilder.AddRazorOptions((options) =>\r\n            {\r\n\r\n                var previous = options.CompilationCallback;\r\n                options.CompilationCallback = (compilationContext) =>\r\n                {\r\n                    if (previous != null)\r\n                    {\r\n                        previous(compilationContext);\r\n                    }\r\n\r\n                  compilationContext.Compilation.AddReferences(\r\n                        MetadataReference.CreateFromFile(assy.Location));\r\n                };\r\n            \r\n\r\n                var  fileProvider = new EmbeddedFileProvider(assy, \"Gluon.Module.ThemeSwitcher\"));\r\n                options.FileProviders.Add(fileProvider);\r\n            });\r\n\r\n```\r\n\r\nIn my application, I search for, and invoke the ViewComponent dynamically - as the application doesn't have a dependency on it:\r\n\r\n```\r\n\r\n public class ViewComponentHelper : IExtendedViewComponentHelper\r\n    {\r\n        private readonly IViewComponentDescriptorCollectionProvider _descriptorProvider;\r\n        private readonly IViewComponentSelector _selector;\r\n\r\n        public ViewComponentHelper(\r\n          IViewComponentDescriptorCollectionProvider descriptorProvider,\r\n          IViewComponentSelector selector)\r\n        {\r\n            _descriptorProvider = descriptorProvider;\r\n            _selector = selector;\r\n        }\r\n\r\n        public Task<IHtmlContent> InvokeIfExistsAsync(IViewComponentHelper componentHelper, string name, object arguments = null)\r\n        {\r\n            if (!Exists(name))\r\n            {\r\n                return Task.FromResult<IHtmlContent>(new HtmlString(string.Empty));\r\n            }\r\n\r\n            if (arguments == null)\r\n            {\r\n                return componentHelper.InvokeAsync(name, null);\r\n            }\r\n\r\n            return componentHelper.InvokeAsync(name, arguments);\r\n\r\n        }      \r\n\r\n        private bool Exists(string name)\r\n        {\r\n            var comp = _selector.SelectComponent(name);\r\n            bool exists = comp != null;\r\n            return exists;\r\n        }     \r\n    }\r\n\r\n```\r\n\r\nThe `ViewComponent` get's invoked, but there is this error during Razor compilation:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/3176632/16425653/89c42b86-3d5d-11e6-958e-2ef5c64f7bdb.png)\r\n\r\nAny ideas what the problem might be?\r\n\r\nHere is the contents of the Razor file:\r\n\r\n```\r\n@addTagHelper \"*, Microsoft.AspNetCore.Mvc.TagHelpers\"\r\n@model Gluon.Module.ThemeSwitcher.ViewModels.ThemeSwitcherViewModel\r\n\r\n@{\r\n    ViewData[\"Title\"] = \"Gluon\";\r\n}\r\n\r\n<li class=\"dropdown themeswitcher\" data-bind=\"visible: $root.visible\">\r\n  \r\n</li>\r\n\r\n```\r\n\r\nIf I remove that `addTagHelper` line in the razor file, it then complains about it again in `_Layout.cshtml`\r\n\r\n![image](https://cloud.githubusercontent.com/assets/3176632/16425820/3b9289e8-3d5e-11e6-80b7-872ad998472f.png)\r\n\r\nIf I remove it from there too, it seems to work. Can you not have duplicate addTagHelper calls or something in the View heirarchy?\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"}}
{"actor":{"display_login":"dazinator"}}