Web publish can't find Microsoft.Build.Framework - c#

I'm using VS2017 with an ASP.NET project that I've inherited from another developer. I have the publish functionality set up to publish to a folder. This has all been working great until now.
The previous developer used EntityFramework, though all of the references were broken when I got the project, so I had to piece together what version. I'm using 6.2.0 currently and everything works fine. He apparently was using the automatic migration functionality. I've continued using this, but have had a couple situations where I had to enable data loss. I really don't want to do this, so the suggested path is to enable migrations and add the actual migrations. I'm not new to OR Mappers, but I am new to EF, so migrations are pretty new to me. In fact, it's been an uphill battle just to get things to work the way the docs say they are supposed to (see this thread)
So, now I am to the point of having my initial migration data. It seemed like the next step is to get this released to our dev server and then to our production server. So, being that I've used the publish functionality many times before with this project, I figured it would just work. Well, that's not the case now due to the changes I did to get EF migrations working.
The publish goes until it does this:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p
C:\Users\Dan\Documents\Source\Repos\web-
app\WebApp\obj\Release\AspnetCompileMerge\Source -u
C:\Users\Dan\Documents\Source\Repos\web-
app\WebApp\obj\Release\AspnetCompileMerge\TempBuildDir
/global.asax(1,0): Error ASPPARSE: Could not load file or assembly
'Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system
cannot find the file specified.
ASPNETCOMPILER(0,0): Error ASPRUNTIME: Could not load file or assembly
'Microsoft.Build.Framework, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system
cannot find the file specified.
The first thing that struck me as interesting is that in order to get migrations to work, I had to install Microsoft.Build.Framework 15 (specifically I installed 15.1.1012 using nuget and then tried updating that to the latest, which is now 15.8.166). Seemed like more than a coincidence that this is a different version of the same library that is in the errors.
I saw some mention of needing to edit devenv.exe.config to change relative paths to absolute (here), but this didn't help.
I verified in the GAC that 4.0.0.0 is there. Apparently so is 14.0.0.0. From what I understand, installed versions that are less than 15 should be in the GAC.
I made sure Microsoft.Build.Framework was added (via nuget) to both my web app project as well as the project that has the EF context and migrations. The version 15 of Microsoft.Build.Framework was listed in both projects as a reference and was automatically set to Copy Local.
I tried changing the version referenced in my web app to 4.0.0.0, which initially had Copy Local set to false. Didn't help. Changed the 4.0.0.0 reference to Copy Local. This time, I'm met with a single error of:
Could not load file or assembly 'Microsoft.Build.Framework,
Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one
of its dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
Now, my thought was since it looks like multiple versions are involved, maybe it should be taken care of with a binding redirect. I rarely have to deal with binding redirects, so I'm not much of an expert, but I did look at the web.config and it appears something (I'm assuming Nuget install of Microsoft.Build.Framework 15) had already entered the following:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-15.1.0.0" newVersion="15.1.0.0" />
</dependentAssembly>
So, considering that 4.0.0.0 is in the GAC and considering there's a redirect that I believe would redirect any 4.0.0.0 reference to 15.1.0.0, why would I get errors about not being able to find 4.0.0.0? Is there something I'm missing? I assume this must be related to something aspnet_compiler.exe is doing on a publish, since I can build and test the app fine on my development machine.

I had the exact same issue as described by OP.
Problem was solved by installing Microsoft Build Tools 2015
For me issue happened after moving from VS 2015 to VS 2017. However, I have heard few people reporting the same when a project created in VS 2015 is attempted to be published in VS 2017.

It's a Microsoft package issue, Microsoft seems to phase out support of older Nuget versions. This solution worked for me. Issue disappeared and now builds successfully.
In your Azure Build Pipeline > NuGet tool installer step, change Version of NuGet.exe to install to a newer version, like 5.4.0.
Check Nuget's latest ReleasedAndBlessed version at https://dist.nuget.org/tools.json.

In my case removing bindingRedirect from web.config and then installing latest nuget for Microsoft.Build.Framework worked like a charm.

Like the OP, I have a reference to Microsoft.Build.Framework v15 and I found that simply ensuring there are no assembly redirects for the Microsoft.Build.Framework assembly in the web.config allows my deployments to work. Having a redirect breaks deployments because we do the ASPNETCOMPILE stage to ensure views syntax is correct and the build breaks there with the OP's error message.
Unfortunately, Visual Studio 20XX loves to silently re-add an assembly redirect for it to my web.config with every nuget operation, and I have to remove it every stinking time, usually after a failed build reminds me:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-15.1.0.0" newVersion="15.1.0.0" />
</dependentAssembly>

My issue was uber specific but might help someone:
I was using Reflection to do some operations dynamically, and for that I was loading assemblies like this:
var types = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(p => (typeof(IMandatorId).IsAssignableFrom(p) || typeof(INullableMandatorId).IsAssignableFrom(p))
&& typeof(IEntityModel).IsAssignableFrom(p))
.ToList();
However the GetTypes() method would fail for a specific assembly, which in my case was linked to a specific nuget package. I removed the package and stuff started working again.
For those interested the package was:
Microsoft.VisualStudio.Web.CodeGeneration
and problems started appearing after I upgraded all packages to .net 6

Related

Conflict Newtonsoft.Json 6.0.0.0 and 12.0.0.0 in Web Application with Web Api, C#

I have started a new Web Application in Visual Studio 2019. I have added a Web Api. Shortly after or at the same time (can't remember), I startet getting warnings like this:
Warning No way to resolve conflict between "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Choosing "Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily.
I noticed but did not do anything as I decided to wait until it gave me problems.
And that is now...
I am about to use a JSon object but when writing this:
JObject jObject = JObject.Parse(result);
The compiler gives me this error:
Error CS0433 The type 'JObject' exists in both 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' and 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
I have searched the web and my conclusions are as follows:
It looks like it is Microsoft.AspNet.WebApi.Client that is the only package installed, that has a dependency on Newtonsoft.Json (>= 6.0.4)
I have installed Newtonsoft.Json (12.0.3)
In Solution Explorer. In reference list, I have only 1 reference. And that is the one for 12.0.3.
In Web.Config I have this entry (and only this for Newtonsoft.Json).
<dependentAssembly><assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/></dependentAssembly>
In my .csproj I can see 3 different references in 3 different ItemGroups:
One for v. 12.0.0.0
One for v. 12.0.2
And one for v. 12.0.3
I tried to uninstall package Newtonsoft.Json, but is not allowed as other packages are dependent on this.
I have runned this command: Update-Package Newtonsoft.Json in the Package Manager Console, which told me, that no new updates were available.
And now, I have runned out of ideas. I am stucked. Anyone knows what to do?
****New update****
I found the 6.0.0.0. Please have a look at the picture:
Here in resources I double clicked the Newtonsoft.Json reference and in the object browser I can see both 6.0.0.0 and 12.0.0.0.
As you can see, both 6.0.0.0 and 12.0.0.0 are present. 6.0.0.0 is somewhere on my C:-drive inside a SDK.
I have tried to delete the file. My project got nuts. Then I replaced that file with the 12.0.0.0 from my project. This gave me the error that assemplies did not match.
I finally copied the old .dll back. And is a bit stucked again.
Any ideas?
Okay, I fixed it.
I had 2 references in my .csproj file to Newtonsoft.Json. One pointed at packages......\xxx.12.0.3 and one pointing at packages......\xxx.12.0.2.
Both of them was above 6.0.0.0 which was the error I got. So I ignored them.
But acutally, in my project I had only 12.0.3 folder and no 12.0.2 folder. So the reference did not work and VS tried to find another place to look.
I guess it looks around, maybe using the GAC but finally it ended up deep down my local drive in one Azure SDK and found Newtonsoft.Json 6.0.0.0. And that was the problem.
I removed the 12.0.2 reference from my .csproj and finally it worked.
The issue usually comes from two different projects that use different versions of the same library.
Both of those projects are then referenced to another one and the warning effectively warns you that something like this might happen.
Go to the solution and right click - manage nuget packages.
Go to the consolidate tab. Check that newtonsoft is there. If it is, install the same package to all projects.
If that doesn't work, check your projects for added references that don't come from a nuget and remove those too.
In my case, I had to edit the .csproj and look for Newton references. I found out that Antlr3 had a HintPath to an old version. Even the package not existing.

Cannot load System.ComponentModel.Annotations from OrmLiteConfigExtensions (ServiceStack.OrmLite.Core)

I get a runtime error when using ServiceStack.OrmLite.Core package (5.4.1) and trying to get a ModelDefinition (ServiceStack.OrmLite.ModelDefinition) by doing:
var model = ModelDefinition<T>.Definition;
The error reads as follows:
System.IO.FileLoadException: 'Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
I have tried to install nuget System.ComponentModel.Annotations (4.5.0.0 since 4.2.0.0 isnt available) to no avail.
I have also tried various fixes suggested when encountering System.IO.FileLoadException, but nothing works.
The project is a .Net Framework 4.7.1 project but .Net Standard projects are included in the solution so I need to run the .Core version of ServiceStack.OrmLite.
I have tried this on two workspaces (two separate machines), (1) as described above, and (2) where no .Net Standard projects are in the solution.
On the (2) machine it works when running the non Core version of ServiceStack.OrmLite, but switching to ServiceStack.OrmLite.Core the runtime error occurs.
Does anyone have any ideas?
Eventually I figured it out…
As It turns out ServiceStack.OrmLite.MySql.Core requires System.ComponentModel.Annotations version 4.2.0.0 as the error message clearly states. Normally it works to install a version equal to or greater than what’s required but in this case none of that worked. And for some reason it seems as the latest release included in FX is 4.0.0.0 (or at least that’s what I get when I include the assembly version of it.) There is also a nuget installing version 4.5.0.0, but the outcome is the same.
I have no idea why it works out of the box using the FX versions of ServiceStack.OrmLite.MySql, but when using the Core version as I do, I find no way of avoiding this without the following fix:
In my startup project, I need to add an assembly binding telling ServiceStack.OrmLite.MySql.Core that System.ComponentModel.Annotations version 4.2.0.0 “redirects” to 4.0.0.0 (of the same assembly). It looks like this:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
I'm sure there are people out there who can explain the details around this, me not one of them but nonetheless… adding this to the startup projects app.config will do the trick.
In trying to repro this I've resolved a different issue with the ASP.NET Core Apps on the .NET Framework templates referencing the latest v5.4.1 MyGet packages where the Tests .csproj should be referencing the new ServiceStack.Kestrel.Core package instead of ServiceStack.Kestrel, i,e:
<PackageReference Include="ServiceStack.Kestrel.Core" Version="5.*" />
Which is now updated in all .Core templates. To access the latest v5.4.1 packages on MyGet you'd need to clear your NuGet packages cache:
$ nuget locals all -clear
Then install latest web-corefix project using the new web .NET Core tool:
$ dotnet tool install --global web
$ web new web-corefx WebCoreFx
I've then added a reference to OrmLite MySql in WebCoreFx.csproj:
<PackageReference Include="ServiceStack.OrmLite.MySql.Core" Version="5.*" />
And updated Startup.cs to register the MySql provider, create and select from a table simple table and access its ModelDefinition<T>.Definition API:
class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
public override void Configure(Container container)
{
SetConfig(new HostConfig {
DefaultRedirectPath = "/metadata",
DebugMode = AppSettings.Get(nameof(HostConfig.DebugMode), false)
});
container.Register<IDbConnectionFactory>(c => new OrmLiteConnectionFactory(
"Server=localhost;Database=test;UID=root;Password=test;SslMode=none",
MySqlDialect.Provider));
using (var db = container.Resolve<IDbConnectionFactory>().OpenDbConnection())
{
db.DropAndCreateTable<Person>();
db.Insert(new Person {Id = 1, Name = "Name"});
var s = db.Select<Person>().Dump();
s.PrintDump();
}
var model = ModelDefinition<Person>.Definition;
model.Name.Print();
}
Which works as expected and runs without issue.
If you still have issues can you upload a MCVE on GitHub I can run locally to repro the issue.
I was having this issue and others related to SqlClient not supported. Make sure the regular .net app is set to use PackageReference instead of packages.config. If not migrate it. This solved my issues without having to put in a bunch of binding redirects.

Program is referring to a different version of Newtonsoft.JSON although a different version is loaded

I was working on a project to Self host a Web API project.
There are two packages 1) Microsoft.AspNet.WebAPi.SelfHost
2) Microsoft.AspNet.WebApi. I had run into a problem where two different versions of NewtonSoft.Json had been installed by the above packages and it showed a compile-time warning as well as a run time exception. If I install Microsoft.AspNet.WebAPi.SelfHost before Microsoft.AspNet.WebApi then Newtonsoft.Json version 6.0.0.0. is installed by the former and the version 11.0.0.0 by the later which gives the error. but if I install Microsoft.AspNet.WebApi, then version 11.0.0.0 is installed and Microsoft.AspNet.WebAPi.SelfHost doesn't install Newtonsoft.Json but I still get the following error
"Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its >dependencies. The located assembly's manifest definition >does not match the assembly reference. (Exception from >HRESULT: 0x80131040)/nSystem.IO.FileLoadException"
although the following is the entry in my web.config reference
"culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"
bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />"
I am really not getting why it is referring to version 6.0.0.0 when a newer version is installed. And if I need both the versions how do I refer to each without causing compiler issues.
Edit: Another thing to mention here is that it errors only after publishing the file but if I run it in release mode, no issue is occurring.
I have tried this after creating a new folder from scratch.
Edit: I have also tried checking the GAC. Newtonsoft.JSON is not available in the GAC. Can anyone tell how to check the manifest/config file of a third-party package like the Microsoft.AspNet.WebAPi.SelfHost
Edit: I also checked the solutions from the linked thread, but it didn't help.
Edit: I just now edited Microsoft.Owin from version 2.0.2 to version 4, but strangely after publishing and running it is still referring to version 2. I checked web.config and package.config, they have correct assembly redirects as well as correct package. So i guess there is some other place where it is not getting updated. Anyone can help me on this?

Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0

After update to the new package Microsoft.EntityFrameworkCore.SqlServer 1.1.2 I got error when try to create DBContext:
System.IO.FileLoadException occurred HResult=0x80131040
Message=Could not load file or assembly
'Microsoft.Extensions.DependencyInjection.Abstractions,
Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or
one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040) Source=Microsoft.EntityFrameworkCore StackTrace: at
Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions
options) at
Services.Infrastructure.Data.SqlServerDbContext..ctor(DatabaseOptions
databaseOptions) in
C:\src\backend\Packages\Services.Infrastructure\Data\SqlServerDbContext.cs:line
16 at
Translations.Api.Data.TranslationsDbContext..ctor(DatabaseOptions
databaseOptions) in
C:\src\backend\Modules\Translations\Translations.Api\Data\TranslationsDbContext.cs:line
16
My base DbContext
public class SqlServerDbContext : DbContext
{
private readonly DatabaseOptions _databaseOptions;
protected SqlServerDbContext(DatabaseOptions databaseOptions)
{
if (string.IsNullOrEmpty(databaseOptions.ConnectionString))
throw new Exception("Database connection string is missed.");
_databaseOptions = databaseOptions;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(_databaseOptions.ConnectionString);
}
}
Database options that I use
public class DatabaseOptions
{
public string ConnectionString { get; set; }
}
Place where I create instance of context
var dbOptions = new DatabaseOptions { ConnectionString = _connectionString };
DbContext = (TContext) Activator.CreateInstance(typeof(TContext), dbOptions);
// where TContext is derived class from SqlServerDbContext
All my packages are updated. Visual Studio 2017 15.2 (26430.6). Before upgrade to 1.1.2 everything works fine. Please help to solve the problem.
Since you're using the project in a .net framework library, there's an issue with auto-generated binding redirects (might be resolved in the upcoming 15.3 update / 2.0 .net core CLI). To work around it, add this in your cpsroj file (preferably before any <Import> element for a .targets file if present):
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
This should force MSBuild to create / update a YourProject.dll.config file containing the necessary binding redirects.
If you're working with Azure Functions in .NET Core this will work
If you're not using the .net framework library, but the .net core library, the accepted solution will not work because "you shouldn't be setting the property AutoGenerateBindingRedirects on a netcoreapp project as binding redirects aren't even a thing in netcoreapp, they are only a concept in .NET Framework" (source: https://github.com/microsoft/ApplicationInsights-dotnet/issues/1699#issuecomment-592693436).
Try this:
Uninstall Microsoft.Extensions.DependencyInjection.Abstractions
Uninstall Microsoft.Extensions.DependencyInjection
Although this seems like a radical solution, it works because the library is already indirectly installed through Microsoft.Azure.Functions.Extensions:
Important: Do not try to solve this issue by upgrading .NET Core from 3.1 to 5.0. Azure functions are still not supported in .NET 5.0. A patch is coming in early 2021:
https://github.com/Azure/azure-functions-host/issues/6674#issuecomment-712596112
EDIT: Azure functions are now supported in .NET Core (unless you're using durable entities, in that case you'll have to wait for .NET 6.0):
Today (10/3/2021), we announced support for running production .NET 5 apps on Azure Functions.
https://techcommunity.microsoft.com/t5/apps-on-azure/net-on-azure-functions-roadmap/ba-p/2197916
I Googled my exception below, and it brought me to this stakoverflow post.
System.IO.FileNotFoundException: 'Could not load file or assembly
'Microsoft.Extensions.OptionsModel, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=adb9793829ddae60' or one of its dependencies. The
system cannot find the file specified.'
I had the relevant Binding Redirects but if I Delete all bin/obj folders it worked fine afterwards.
This is an old thread but I had a similar same issue after I updated my Azure function from dotnet core version 3 to 3.1.
Error message: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.1.9.0
In this case you need to update the Azure function version to 'v3' in .proj file.
I've been getting a similar issue using Azure functions 3.0.13
I kept getting the error System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Options, Version=6.0.0.0
I added a direct reference to the package via NuGet and then had to add this to my project.csproj file to make everything work. I can't take credit for this fix. I found it somewhere else a while ago, but I can't recall from where.
<PropertyGroup>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
I was having this problem. But the packet was Microsoft.Extensions.Primitives.
In my case I installed it in my Project and in my Project test from nuget. Maybe could help someone.
For me, what did it was to downgrade all the packages support .Net Standard to 2.2.0 from 3.x.x
i guess the 3.x packages relevant to a different version of .Net standard which does not support ,net framework.
It is a cracy thing, but for me what really worked was upating all packages that begins with Microsoft, since I updated my project to run over .Net 4.7.2, Then I just right click on Solution and Clean and Build again.
If Luis Gouveia solution doesn't work for you, try downgrading other dependencies included in the project. There are some compatibility issues with .NET standard.
Ref: https://github.com/Azure/Azure-Functions/issues/1729
I had same problem and finally fixed with below solution
Install "System.ComponentModel.Annotations" version 4.4.1 in a temporary project to get the file of "System.ComponentModel.Annotations.dll", then copy this file to your real project and then change your project reference to point this file instead of the original NuGet path
Then in your web.config add below code that redirec
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<publisherPolicy apply="no" />
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.2.1.0" />
</dependentAssembly>
</assemblyBinding>
I was working on my simple .Net 5.0 Console app and while modifying my project's namespace the "auto-installation" added only the Microsoft.Extensions.DependencyInjection.Abstraction not the package nuget Microsoft.Extensions.DependencyInjection
It took me a while to realise that...
Here some solves :
1-I updated my packages from NuGet to latest version and working 100%.
2- make these editing in config :
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
3-Delete all bin and objct folders then clean solution and finally run , hope this will be work .
I had the same problem with a .Net Framework website that included an assembly using EFCore 3.1.22. I resolved the problem by putting the assembly redirects in the web.config.

How can I get my Web API app to run again after upgrading to MVC 5 and Web API 2?

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).
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
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.

Categories