简体   繁体   中英

OWIN app on new (SDK) csproj format

While converting an OWIN app to the new csproj format I hit a few issues. The first issue had to do with the changed output directory (since it now includes the runtime in the path). This threw the following error:

Could not load file or assembly 'Microsoft.Owin.Host.SystemWeb' or one of its dependencies. The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Owin.Host.SystemWeb' or one of its dependencies. The system cannot find the file specified.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

I was able to fix this by setting the path in the Web.config:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <probing privatePath="bin/net461" />
  </assemblyBinding>
</runtime>

After that I am now confronted with this issue:

The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- The given type or method 'ClientWebAPI.Startup' was not found. Try specifying the Assembly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.EntryPointNotFoundException: The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- The given type or method 'ClientWebAPI.Startup' was not found. Try specifying the Assembly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

I have declared the entry point using the assembly attribute:

[assembly: OwinStartup(typeof(API.Startup))]
namespace API
{
    public class Startup
    { /*...*/ }
}

The "Sdk" style csproj, sometimes called the VS2017 project format, does not yet support ASP.NET 4 projects. See the following issues:

There are two layers of issues here: (1) MSBuild and (2) Visual Studio. If you understand how targets and imports work well enough, you could workaround (1) and make the Sdk style csproj work for an Owin project.

The more difficult part is (2) - Visual Studio. When switching to the Sdk style project, under the hood, VS is switching to an entirely new implementation of the project system, the one that is open sourced in https://github.com/dotnet/project-system . This project system does not yet fully support ASP.NET 4 projects.

You can workaround (2) by using Microsoft.Owin.SelfHost instead of using Microsoft.Owin.Host.SystemWeb. To make using Microsoft.Owin.Host.SystemWeb work, VS needs to know how to generate web.config and applicationhost.config file for IIS Express, how to launch the IIS Express site, and attach to process once launched. Much of that is not ported to the new project system, and I'm not sure if it will be. The new project system was designed to work with ASP.NET Core which uses a very different method for launching and configuring IIS Express.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM