Search code examples
asp.net-corednx

asp.net 5 project targeting dnx46 wont build


I have a solution which contains an asp.net 5 app, a code library, and a test library. The libraries are also the new project.json style. I am not really sure how to refer to these libraries to distinguish them from the existing library project structure.

Anyway, all three projects were targeting dnx451/net451. I decided to try targeting dnx46/net46. The libraries build, but the asp.net dnx app fails. The error is:

The design time host build failed with the following error: Object reference not set to an instance of an object.

It is referencing the file Microsoft.DNX.targets at line 166.

There is another error that just says, "Object reference not set to an instance of the object." It says line 1, but doesn't reference a file.

To test I created a new solution with and empty asp.net 5 project and 2 class libraries. I changed dnx451 to dnx46, and net451 to net46, and it compiles fine. I am not sure what in my existing project is causing this error, or where to start looking.

By the way, dnx46/net46 are the only frameworks targeted. I have removed the core frameworks.


Solution

  • What a load of trial and error. Turns out the issue was the razor precompilation module as described here, http://davidzych.com/view-compilation-in-aspnet-5-with-the-razorprecompilemodule/.

    You can read the github issue here, https://github.com/aspnet/dnx/issues/3003.

    I first tried to comment out the precompilation class. However just that fact that the file was there, made dnx throw the error. I removed the precomilation file and now it compiles fine.

    EDIT: Alternatively you can add dnx451 back into your project, along with dnx46 and then the precomilation module will work fine.