Skip to content

dnx add migration, IHostingEnvironment.WebRootPath is null #4494

Closed as not planned

Description

@dazinator

I have an ASP.NET 5 WebApplication, and an EF 7 db context (RC 1 Final) in a seperate project.

When I CD to my web project directory, and run dnx ef migration add InitialMigration -p SomeEfDataProject

I am getting an exception to do with the fact that during initialisation, my application makes use of IHostingEnvironment.WebRootPath which is Null within the context of executing the dnx migration command line.

Shouldn't this be set to something?

My application startup logic uses IHostingEnvironment.WebRootPath to figure out a path to a local drop folder, where plugin (mef) components can be dropped and loaded during app startup.

Activity

  1. dazinator commented on Feb 4, 2016

    @dazinator
    Author

    I have worked around this by chucking this in my startup logic, seems to solve it.

       if (string.IsNullOrWhiteSpace(_env.WebRootPath))
       {
           _env.WebRootPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "wwwroot");
       }
  2. rowanmiller commented on Feb 5, 2016

    @rowanmiller
    Contributor

    cc @bricelam... seems like there probably isn't much we can do here?

  3. dazinator commented on Feb 5, 2016

    @dazinator
    Author

    Setting WebRootPath to an empty value or a fake value, might help. I don't think when people are developing an asp.net 5 web application that they would expect the 'WebRootPath' to potentially be Null. In the normal case this is always set to something. In the EF migration case, because it's not it will catch people out with null ref exceptions.

  4. bricelam commented on Feb 5, 2016

    @bricelam
    Contributor

    We could provide a better value for WebRootPath, but it would still be wrong for some projects. We could also go back to taking a dependency on Hosting, but there sure was a lot of pushback...

  5. dazinator commented on Feb 6, 2016

    @dazinator
    Author

    but it would still be wrong for some projects

    Not sure I understand. The webroot for an asp.net 5 (dnx) project is specified in the project.json file, so is this not a simple case that EF (migrations), when running the project, can check for this value in the project.json file and set the WebRootPath on IHostingEnvironment appropriately. That logic should then result in this value being set correctly for all dnx based projects unless I am missing something!

  6. rowanmiller commented on Feb 12, 2016

    @rowanmiller
    Contributor

    Closing in favor of a more general issue to sort out how we interact with Startup #4546

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions