c# - Azure 事件日志 - TargetInitationException 和奇怪的消息

标签 c# .net asp.net-mvc iis azure

我在将网站发布到 Windows Azure 时遇到困难,因此决定打开应用程序日志记录。

虽然网站发布完成,但在Azure云上启动应用程序时抛出异常;事件日志中出现以下事件:

基本上,事件日志中的这一特定事件有一些值得注意的事情

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(Action1 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, 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(Action1 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, 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)

关于此消息,有几件事引起了我的注意: 1. 应用程序日志包含对我的硬盘驱动器/dropbox 文件夹上的文件的引用。这是没有意义的,因为这是云的部署运行! 2. 由于某种我不知道的原因,应用程序正在尝试加载 Microsoft.Owin.Security 版本 2.0.0 程序集,尽管我已在项目中使用 copy local = true 安装了版本 2.1.0.0。我还更新了 web.config 中的程序集绑定(bind),如下所示:

<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>

根据上面的堆栈跟踪,以下是导致抛出错误的代码:

 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();
    }
}

该系统在我的开发环境中完美运行。

我想我在试图解决这个难题时可能已经崩溃了。我还尝试在 list 文件中进行挖掘并尝试不同的 nuget 版本,但是可惜......没有成功。

最佳答案

问题似乎与由于版本控制问题而损坏的项目/ list 文件有关。我的假设是以下一系列事件把事情搞砸了:

  1. 更新了几个 Nuget 包

  2. 已将代码推送到源代码管理。

  3. 从源代码管理将代码恢复到以前的版本。

我相信在此过程中的某个地方,配置/ list /dll 文件没有以一致的方式处理,并导致了我的 clusterbeep。

我的解决方案是恢复到项目的早期工作版本,然后手动将代码更改合并到解决方案中(使用 WinMerge)。

虽然这是一项痛苦且耗时的事件,但这似乎解决了所有问题。

给其他遇到类似问题的人的额外提示:

  1. 在错误列表窗口中启用“Wanrings”。

  2. 将构建输出详细程度设置为“详细”。在 VS2013 中,转到“工具”>“选项”>“项目和解决方案”>“生成并运行”。将“MSBuild 项目构建输出详细程度”选项设置为“详细”。检查构建后的输出是否有任何冲突,因为这还将准确指出冲突程序集所在的位置。 (解决方案中的项目会被分配一个编号,并且与每个项目相关的操作都会用该编号进行相应标记)。

  3. 为 Azure 上的网站设置详细的应用程序日志记录。为此,从 Azure 管理门户中选择您的站点,单击“配置”,向下浏览到“应用程序诊断”

关于c# - Azure 事件日志 - TargetInitationException 和奇怪的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23440968/

相关文章:

c# - 两个 Controller 方法之间不明确

c# - List.Contains 上的索引越界

c# - 在不同的CPU内核上执行上下文切换和线程

c# - Linq OrderByDescending ThenByDescending 问题

asp.net-mvc - 与 Ninject 的集成测试

c# - 通过 MVC Controller 返回序列化为 JSON 的大型集合

c# - EntityType 'DbGeography' 没有定义键

c# - 为什么我的流在我自己解锁之前就被解锁了?

jquery - 将 jquery/javascript 与 asp.net MVC View 分开?

c# - LInq to SQL - 部分类 - C#