3
votes

I have very simple ASP.NET Project that works just fine when I run it from Visual Studio, but after I publish to Azure Web App I get this error

Could not load file or assembly 'Microsoft.Owin.Security, Version=2.0.1.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)

I looked everywhere and I am not using - at least not intentionally - this assembly and it's not listed on Web.config or Package.config or anywhere if I do a search within the solution.

I really don't know what I am missing here. Maybe a configuration from Azure side.

Here is the Stack Trace

[FileLoadException: Could not load file or assembly 'Microsoft.Owin, Version=2.1.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)] SampleWebApp.Startup.ConfigureAuth(IAppBuilder app) +0 SampleWebApp.Startup.Configuration(IAppBuilder app) +5

[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +92 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +136 Owin.Loader.<>c__DisplayClass12.b__b(IAppBuilder builder) +66 Owin.Loader.<>c__DisplayClass1.b__0(IAppBuilder builder) +123 Microsoft.Owin.Host.SystemWeb.<>c__DisplayClass2.b__0(IAppBuilder builder) +71 Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action1 startup) +462 Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(Action1 startup) +40 Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +70 System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +115 Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +106 System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +537 System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172 System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +364 System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +290

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +4531288 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +94 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +191

1

1 Answers

5
votes

ok, I found the root of the problem.

I had a previous ASP.NET Web Application using Authentication - I can't remember which one exactically. After a few changes I published to Azure and everything was working fine.

Later on, I changed to use token for Authentication so I decided to remove the existing ASP.NET Web Application that uses Authentication and created a new one without it. After publishing to Azure I start getting the error described on the question above. Of course my new Web App didnt have any reference to any authentication but I was deplying to Azure without removing previous files.

So, what I did was publishing again but this time in the publishing Settings I click on File Publish Options and checked the option Remove additional files at destination. I would assume that this option remove any existing files and references from the first Web App i created using Authentication. Now my new Web App works just fine.

Remove additional files at destination