Skip to content

Controllers in entry assembly are not getting discovered automatically in 3.0 #4175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
natemcmaster opened this issue Nov 21, 2018 · 1 comment
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Comments

@natemcmaster
Copy link
Contributor

Likely the result of #4061.

Controllers are not getting discovered in simple apps, such as dotnet new mvc. Instead, the app fails with 404.

Workaround

        public void ConfigureServices(IServiceCollection services)
        {
			/// ...
            var mvcBuilder = services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
            ConfigureControllers(mvcBuilder.PartManager);
        }

		
        private void ConfigureControllers(ApplicationPartManager applicationPartManager)
        {
            var thisAssembly = typeof(Startup).Assembly;
            var partFactory = ApplicationPartFactory.GetApplicationPartFactory(thisAssembly);
            foreach (var part in partFactory.GetApplicationParts(thisAssembly))
            {
                applicationPartManager.ApplicationParts.Add(part);
            }

            var relatedAssemblies = RelatedAssemblyAttribute.GetRelatedAssemblies(thisAssembly, throwOnError: true);
            foreach (var assembly in relatedAssemblies)
            {
                partFactory = ApplicationPartFactory.GetApplicationPartFactory(assembly);
                foreach (var part in partFactory.GetApplicationParts(assembly))
                {
                    applicationPartManager.ApplicationParts.Add(part);
                }
            }
        }

cc @pranavkm @Eilon @mkArtakMSFT - this seems like a critical bug to fix for preview1

@natemcmaster natemcmaster added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Nov 21, 2018
@natemcmaster natemcmaster added this to the 3.0.0-preview1 milestone Nov 21, 2018
@natemcmaster natemcmaster self-assigned this Nov 21, 2018
@natemcmaster
Copy link
Contributor Author

The fix appears to be simple: aspnet/Mvc#8751

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

No branches or pull requests

1 participant