Skip to content

The view 'Index' was not found #22

Open

Description

@Genbox

I noticed that when I set the output path of an assembly, the views no longer load.

Steps to reproduce:

  1. Download the ready to use sample at http://extcore.net/files/ExtCore-Sample-1.0.0-alpha16.zip
  2. Change line 3 in ExtCore-Sample\src\WebApplication.ExtensionA\project.json from
    "buildOptions": { "embed": [ "Styles/**", "Views/**" ],
    To:
    "buildOptions": { "embed": [ "Styles/**", "Views/**" ], "outputName": "Something.ExtensionA"},
  3. Remove WebApplication.ExtensionA.dll from the Extensions folder of WebApplication
  4. Move Something.ExtensionA.dll from the output folder of the WebApplication.ExtensionA project into the Extensions folder in WebApplication

You should receive an error like this:
InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Views/ExtensionA/Index.cshtml
/Views/Shared/Index.cshtml

Activity

  1. DmitrySikorsky commented on Aug 5, 2016

    @DmitrySikorsky
    Member

    Hm, I think it might be related to something like https://github.com/ExtCore/ExtCore/blob/master/src/ExtCore.Mvc/MvcExtension.cs#L122

    Maybe a.GetName().Name returns 'WebApplication.ExtensionA' so resources will have default namespace 'WebApplication.ExtensionA', not 'Something.ExtensionA', but I'm not sure so far.

  2. DmitrySikorsky commented on Sep 4, 2016

    @DmitrySikorsky
    Member

    I have explored this issue and found that when you set outputName to any value your embedded resources still have original names (prefix = project name). So in this case line https://github.com/ExtCore/ExtCore/blob/master/src/ExtCore.Mvc/MvcExtension.cs#L122 will set wrong base namespace so resources will not be discovered. To fix that we need to be able to get original namespace from the assembly. I don't know how to do that so far.

  3. mwgriffiths88 commented on Oct 26, 2016

    @mwgriffiths88

    Ideally grabbing it from the Assembly would be ideal. However, I can't find anything that would work.

    It might be possible to load the correct namespace by getting access to the extension's Startup class and calling this.GetType().GetTypeInfo(). It has properties for Assembly and Namespace which would work for this scenario - I'll investigate a little later on.

  4. DmitrySikorsky commented on Oct 26, 2016

    @DmitrySikorsky
    Member

    Problem is that assembly may have only resources, without any classes. So still don't know how to fix. Maybe we should ask on asp.net core project.

  5. mwgriffiths88 commented on Oct 27, 2016

    @mwgriffiths88

    As far as I can tell the EmbeddedFileProvider works by taking a path like '/Views/Home/Index.cshtml' and transforming it to 'Views.Home.Index.cshtml', and then prepending the baseNamespace to form the full resource name, like 'WebApplication.ExtensionA' .

    It's possible that we could write our own provider that simply queries the GetManifestResourceNames() inside the assembly for the correct resource. The only problem is that there would be a conflict between extensions that contain the same view in the same location - but this problem must already exist with the current setup too?

  6. DmitrySikorsky commented on Oct 27, 2016

    @DmitrySikorsky
    Member

    Yes, there will be a conflict if we have the same view with the same location in the different extensions. And I think it is normal, because the point is that you can specify the views for the extensions inside your main web application of inside the different extensions... It is the way it should work as I think. So your solution may work.

  7. bdparrish commented on Feb 23, 2017

    @bdparrish
    Contributor

    Should this issue be closed?

  8. mwgriffiths88 commented on Feb 23, 2017

    @mwgriffiths88

    The issue still exists, the submitted solution was a workaround and nothing more. I'm happy for the issue to be closed.

  9. DmitrySikorsky commented on Feb 23, 2017

    @DmitrySikorsky
    Member

    Agree with @mwgriffiths88. I will be happy to know how to fix the issue (not workaround).

  10. added this to the 5.0.0 milestone on Aug 8, 2019
  11. modified the milestones: 5.0.0, 6.0.0 on Nov 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions