在将OWIN应用转换为新的csproj格式时,我遇到了一些问题。第一个问题与更改的输出目录有关(因为它现在包括路径中的运行时)。这引发了以下错误:
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.
我能够通过在Web.config中设置路径来解决这个问题:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin/net461" />
</assemblyBinding>
</runtime>
之后我现在面临这个问题:
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.
我已使用assembly属性声明了入口点:
[assembly: OwinStartup(typeof(API.Startup))]
namespace API
{
public class Startup
{ /*...*/ }
}
答案 0 :(得分:1)
“Sdk”风格的csproj,有时称为VS2017项目格式,尚不支持ASP.NET 4项目。请参阅以下问题:
这里有两层问题:(1)MSBuild和(2)Visual Studio。如果您了解目标和导入如何运作良好,您可以解决方法(1)并使Sdk样式csproj适用于Owin项目。
更难的部分是(2) - Visual Studio。当切换到Sdk风格项目时,VS正在切换到项目系统的全新实现,即https://github.com/dotnet/project-system中开源的项目系统。该项目系统尚未完全支持ASP.NET 4项目。
您可以使用Microsoft.Owin.SelfHost而不是使用Microsoft.Owin.Host.SystemWeb来解决方法(2)。要使用Microsoft.Owin.Host.SystemWeb工作,VS需要知道如何为IIS Express生成web.config和applicationhost.config文件,如何启动IIS Express站点,并在启动后附加到进程。其中大部分没有移植到新的项目系统,我不确定它是否会。新项目系统旨在与ASP.NET Core一起使用,后者使用一种非常不同的方法来启动和配置IIS Express。