app.UseCookieAuthentication(new CookieAuthenticationOptions());
未处理的异常:
System.Reflection.TargetInvocationException:调用目标抛出了异常. —> System.TypeLoadException:无法从程序集“Microsoft.Owin.Security,Version = 2.1.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”加载类型“Microsoft.Owin.Security.DataProtection.DpapiDataProtector”.
在Microsoft.Owin.Security.DataProtection.AppBuilderExtensions.CreateDataProtector(Owin.IAppBuilder,string [])< 0x00052>
在Microsoft.Owin.Security.Cookies.CookieAuthenticationMiddleware..ctor(Microsoft.Owin.OwinMiddleware,Owin.IAppBuilder,Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions)< 0x00223>
at(wrapper dynamic-method)object.lambda_method(System.Runtime.CompilerServices.Closure,Microsoft.Owin.OwinMiddleware,Microsoft.Owin.Security.Cookies.CookieAuthenticationOptions)< 0x00048>
at(wrapper managed-to-native)System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object [],System.Exception&)< 0x00067>
在System.Reflection.MonoMethod.Invoke(object,System.Reflection.BindingFlags,System.Reflection.Binder,System.Globalization.CultureInfo)< 0x000d7>
—内部异常堆栈跟踪结束—
在System.Reflection.MonoMethod.Invoke(System.Object obj,BindingFlags invokeAttr,System.Reflection.Binder binder,System.Object [] parameters,System.Globalization.CultureInfo culture)[0x00000] in:0
在System.Reflection.MethodBase.Invoke(System.Object obj,System.Object [] parameters)[0x00000] in:0
在System.Delegate.DynamicInvokeImpl(System.Object [] args)[0x00000] in:0
在System.MulticastDelegate.DynamicInvokeImpl(System.Object [] args)[0x00000] in:0
在System.Delegate.DynamicInvoke(System.Object [] args)[0x00000] in:0
在Microsoft.Owin.Builder.AppBuilder.BuildInternal(System.Type signature)[0x00000] in:0
在Microsoft.Owin.Builder.AppBuilder.Build(System.Type returnType)[0x00000] in:0
在Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create(IAppBuilder builder)[0x00000] in:0
在Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer(Microsoft.Owin.Hosting.Engine.StartContext context)[0x00000] in:0
在Microsoft.Owin.Hosting.Engine.HostingEngine.Start(Microsoft.Owin.Hosting.Engine.StartContext context)[0x00000] in:0
在Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(Microsoft.Owin.Hosting.StartOptions options)[0x00000] in:0
在Microsoft.Owin.Hosting.Starter.HostingStarter.Start(Microsoft.Owin.Hosting.StartOptions options)[0x00000] in:0
在Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services,Microsoft.Owin.Hosting.StartOptions options)[0x00000] in:0
在Microsoft.Owin.Hosting.WebApp.Start(Microsoft.Owin.Hosting.StartOptions选项)[0x00000] in:0
在Microsoft.Owin.Hosting.WebApp.Start [Startup](Microsoft.Owin.Hosting.StartOptions options)[0x00000] in:0
在Microsoft.Owin.Hosting.WebApp.Start [Startup](System.String url)[0x00000] in:0
在HelloWorldNancy.Program.Main(System.String [] args)[0x00000] in:0
[ERROR]致命的UNHANDLED EXCEPTION:System.Reflection.TargetInvocationException:调用目标抛出了异常. —> System.TypeLoadException:无法从程序集“Microsoft.Owin.Security,Microsoft.Owin.Hosting.StartOptions options)[0x00000] in:0
在Microsoft.Owin.Hosting.WebApp.Start(Microsoft.Owin.Hosting.StartOptions选项)[0x00000] in:0
在Microsoft.Owin.Hosting.WebApp.Start [Startup](Microsoft.Owin.Hosting.StartOptions options)[0x00000] in:0
在Microsoft.Owin.Hosting.WebApp.Start [Startup](System.String url)[0x00000] in:0
在HelloWorldNancy.Program.Main(System.String [] args)[0x00000] in:0
解决方法
app.UseCookieAuthentication(new CookieAuthenticationOptions { TicketDataFormat = new SecureDataFormat<AuthenticationTicket>(DataSerializers.Ticket,new AesDataProtectorProvider("testing"),TextEncodings.Base64) });
使用此代码,我的项目再次在Mono中启动.
更新:
你也可以有一个自定义的IDataProtectionProvider,并且所有的owin都使用它:
app.SetDataProtectionProvider(new CustomIDataProtectionProvider());