I'm having difficulty publishing a website to Windows Azure and as such decided to turn on application logging.
Although the publishing of the site completes, an exception is thrown during application startup on the Azure cloud; The following event in the event log results:
Basically there are a few things of note from the just this one specific event from the eventlog
TargetInvocationException
Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Owin.Loader.DefaultLoader.<>c__DisplayClass12.b__b(IAppBuilder builder) at Owin.Loader.DefaultLoader.<>c__DisplayClass1.b__0(IAppBuilder builder) at Microsoft.Owin.Host.SystemWeb.OwinHttpModule.<>c__DisplayClass2.b__0(IAppBuilder builder) at Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action
1 startup) at Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(Action
1 startup) at Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func1 valueFactory) at Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) Could not load file or assembly 'Microsoft.Owin.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at Owin.AppBuilderExtensions.UseExternalSignInCookie(IAppBuilder app, String externalAuthenticationType) at MySiteOnline.Startup.ConfigureAuth(IAppBuilder app) in c:\Users\Andre\Dropbox\Malty IT\Active Projects\MySiteOnline\MySiteOnline\App_Start\Startup.Auth.cs:line 20 at MySiteOnline.Startup.Configuration(IAppBuilder app) in c:\Users\Andre\Dropbox\Malty IT\Active at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Owin.Loader.DefaultLoader.<>c__DisplayClass12.<MakeDelegate>b__b(IAppBuilder builder) at Owin.Loader.DefaultLoader.<>c__DisplayClass1.<LoadImplementation>b__0(IAppBuilder builder) at Microsoft.Owin.Host.SystemWeb.OwinHttpModule.<>c__DisplayClass2.<InitializeBlueprint>b__0(IAppBuilder builder) at Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action
1 startup) at Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(Action1 startup) at Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Boolean& initialized, Object& syncLock, Func
1 valueFactory) at Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)
A couple of things caught my eye with regards to this message: 1. The application logs contain references to files on my hard drive/dropbox folder. This makes no sense as this is a deployment running of the cloud! 2. For some reason unknown to me, the application is trying to load Microsoft.Owin.Security version 2.0.0 assembly, although I have installed version 2.1.0.0 in my project with copy local = true. I have also updated my assembly bindings in web.config as follows:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
</dependentAssembly>
As per the stacktrace above, here is the code which results in the error being thrown:
public partial class Startup
{
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
// Use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication();
}
}
The system works perfectly on my development environment.
I think my mind might have been broken trying to solve this puzzle. I also tried digging around in the manifest file and dabbled with different nuget versions but alas... no success.