6

I upgraded my Web API app to the funkelnagelneu versions using this guidance:

http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

However, after going through the steps (it seems all this should be automated, anyway), I tried to run it and got, "A project with an Output Type of Class Library cannot be started directly"

What in Sam Hills Brothers Coffee is going on here? Who said this was a class library?

So I opened Project > Properties, and changed it (it was marked as "Class Library" for some reason - it either wasn't yesterday, or was and worked fine) to an Output Type of "Windows Application" ("Console Application" and "Class Library" being the only other options).

Now it won't compile, complaining: "Program 'c:\Platypus_Server_WebAPI\PlatypusServerWebAPI\PlatypusServerWebAPI\obj\Debug\PlatypusServerWebAPI.exe' does not contain a static 'Main' method suitable for an entry point..."

How can I get my Web API app back up and running in view of this quandary?

UPDATE

Looking in packages.config, two entries seem chin-scratch-worthy:

<package id="Microsoft.AspNet.Providers" version="1.2" targetFramework="net40" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />

All the others target net451. Could this be the problem? Should I remove these packages?

UPDATE 2

I tried to uninstall the Microsoft.Web.Infrastructure package (its description leads me to believe I don't need it; also, it has no dependencies) via the NuGet package manager, but it tells me, "NuGet failed to install or uninstall the selected package in the following project(s). [mine]"

UPDATE 3

I went through the steps in again, and found that I had missed one step. I had to change this entry in the Application web.config File :

<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>

(from "4.0.0.0" to "5.0.0.0")

...but I still get the same result - it rebuilds/compiles, but won't run, with "A project with an Output Type of Class Library cannot be started directly"

UPDATE 4

Thinking about the err msg, that it can't directly open a class library, I thought, "Sure you can't/won't -- this is a web app, not a project. So I followed a hunch, closed the project, and reopened it as a website (instead of reopening a project).

That has gotten me further, at least; now I see a YSOD:

Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

UPDATE 5

Note: The project is now (after being opened as a web site) named "localhost_48614"

And...there is no longer a "References" folder...?!?!?

As to that YSOD I'm getting, the official instructions (http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2) said to do this, and I quote:

"Update all elements that contain “System.Web.WebPages.Razor” from version “2.0.0.0” to
version“3.0.0.0”
."

UPDATE 6

When I select Tools > Library Package Manager > Manage NuGet Packages for Solution now, I get, "Operation failed. Unable to locate the solution directory. Please ensure that the solution has been saved."

So I save it, and it saves it with this funky new name (C:\Users\clay\Documents\Visual Studio 2013\Projects\localhost_48614\localhost_48614.sln)

I get the Yellow Strip of Enlightenment across the top of the NuGet Package Manager telling me, "Some NuGet packages are missing from this solution. Click to restore from your online package sources."

I do (click the "Restore" button, that is), and it downloads the missing packages ... I end up with the 30 packages.

I try to run the app/site again, and ... the erstwhile YSOD becomes a compilation error:

The pre-application start initialization method Start on type System.Web.Mvc.PreApplicationStartCode threw an exception with the following error message: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..

Argghhhh!!! (and it's not even talk-like-a-pirate day).

UPDATE 7

I'm still curious about why Humpty Dumpty fell down and broke his crown (so to speak), but I finally threw in the towel and created a new project, copying-and-pasting code - and it works fine (VS 2013 and Web API, with REST methods called from a VS 2008, .NET 3.5 client app).

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 5
    Web Api projects are class libraries. It seems you are just not setting the default startup project. – Natan Oct 18 '13 at 18:45
  • Okay, I set Output type back to Class Libary; I right-clicked the project (the only one in the solution) and selected "Set as Startup Project" On trying to run it, I get the same err msg. I then right-clicked the solution and selected "Set Startup Projects..." I have "Single startup project" selected, with the name of that project selected; still the same result, though. – B. Clay Shannon-B. Crow Raven Oct 18 '13 at 18:54
  • Looking at this: http://stackoverflow.com/questions/386831/troubleshooting-program-does-not-contain-a-static-main-method-when-it-clearl, the accepted answer by Quibblesome made me wonder about the file properties. I see that my *.cs files have Build Action set to Compile and Copy to Output Directory set to Do not copy. This is as it should be, right? – B. Clay Shannon-B. Crow Raven Oct 18 '13 at 19:04
  • 2
    I have upgraded a project using this how-to and didn't have any issues. It looks like you changed more things than you should. I recommend you revert your changes, get the latest working version from your source control and try it again. You shouldn't have to change build actions after this upgrade. – Natan Oct 18 '13 at 19:37
  • Natan should be the answer .... during the migration from mvc4 to mvc5 there is on process to unload and reload the project in this step the reloaded project should be defined as start-up project again – 0xFK Oct 19 '13 at 13:36

2 Answers2

10

In the last step on the migration guide did you delete only the MVC4 Project Guid that is specified? I had the same problem as you and when I retraced my steps realised that I had deleted all three of the Guids within in my .csproj file. I restored the other Guids within this element and the solution now recognises it as a MVC application and now works OK. So the line now reads:

<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

Hope that helps

nomadoj
  • 116
  • 1
  • 3
3

I recently ran into this problem, but it was a simple fix. I have multiple projects in my solutions (including several shared PCLs) and when I unloaded the project to change the ProjectTypeGuids, it set a PCL as the default. Right-clicking over my web service project and setting it back to the default startup project fixed it and everything is working.

SpokaneDJ
  • 131
  • 4
  • This, I think, was my problem as well. Only in my case a unit test project was the one that became the default. – Matt Sep 02 '14 at 19:43