5
  1. Using Visual Studio 2013, create a new ASP.NET Web Application project using the MVC template. Verify that the Add View dialog functions by right-clicking the "Views\Home" folder and choosing "Add... View".
  2. Now add a new F# Library project to the solution. The Add View dialog should still function correctly.
  3. Now add a project reference from the MVC project to the F# project by right-clicking the References folder, choosing Add Reference, Then browse to Solution...Projects on the left and checking the F# library project that you just added.

At this point, if you right-click the "Views\Home" folder and choose "Add... View" you will get an error in a pop-up alert box instead of the Add View dialog:

There was an error running the selected code generator: 'Object reference not set to an instance of an object.'

Workarounds include, but are hopefully not limited to:

  • Remove all your references to any F# projects every time you want to add a new view.
  • Unload any referenced F# projects, but leave the project references in place, every time you want to add a new view.

My questions are:

  • Are other people seeing this behavior, or is it just me?
  • Does anyone know of a better work-around than removing references or unloading F# projects?
  • Does anyone know if Microsoft is already working on fixing this? If not should this be reported to the F# team or the Visual Studio team?

Between this issue and the fact that it is still impossible to use NuGet to add an Entity Framework 6 reference to any F# project, I'm starting to get nervous about Microsoft's level of commitment to the F# language.

Joel Mueller
  • 28,324
  • 9
  • 63
  • 88
  • 1
    Feel free to vote for the associated bug report... https://connect.microsoft.com/VisualStudio/feedback/details/806801/add-view-dialog-does-not-work-in-an-mvc-5-project-that-references-an-f-project – Joel Mueller Oct 28 '13 at 19:53
  • Might not be an F# issue: this same error mysteriously started happening for me in VS2013 without warning and without any F# projects at all. If in the context dialog, instead of choosing Add View, I choose Add New Item, then add a View from the New Item dialog, I can add a view. Maybe some registry setting got corrupted. The only thing I did that may be causative was add a Unit Test Project – subsci Jan 31 '14 at 06:57
  • I have the same issue with F# project. Regarding workaround - every time I need a new view I just copy an existing `.cshtml` file, rename it and delete all content. At least I don't need to remove and re-add the reference to my f# project. – takemyoxygen May 04 '14 at 13:15

2 Answers2

6

Not sure if this will help you but check the version of EntityFramework in your solution. I had two projects within my solution and for whatever reason, the web project had EF 6 and the class library project was EF 6.1. Once I uninstalled EF completely from the solution and reinstalled EF 6.1 on both project, the "Add new view" action started working.

Alok Khanna
  • 81
  • 2
  • 5
  • Yep, this was my problem as well. The project with the EDMX was using EF 6.1.1 and the web project was using EF 6.1.3. After updating everything worked as expected. – bic Mar 24 '15 at 12:15
0

I received the same error message when adding views or controllers in a C# & MVC multi-project solution, using EF 6.1 and VS2013 with Update 3. The problem was because the nuget "packages" folder was marked as read only, because it was checked into source control. I checked the entire folder out, making it editable, and it started working fine, allowing me to scaffold straight from VS.

I also received the error message in a web.api project because I forgot to add the Entity Framework connection string to the web.config (it was using Areas and EF was looking in the Area web.config, not the web.config in the root).

Fordy
  • 720
  • 1
  • 7
  • 11
  • It might be related to the MVC post where the error was caused by the missing web.config: http://stackoverflow.com/a/22388052/200824 – Bob Lokerse Aug 28 '15 at 15:00