本文介绍了Azure的Eventlogs - TargetInvocationException和怪异的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有困难的发布网站到Windows Azure,因此决定打开应用程序日志。

I'm having difficulty publishing a website to Windows Azure and as such decided to turn on application logging.

虽然该网站的发布完成后,一个异常期间的Azure云应用程序启动时抛出;在事件日志中得出的下列事件:

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

了异常由调用的目标。在  System.RuntimeMethodHandle.InvokeMethod(对象的目标,对象[]  参数,签名的签名,布尔构造函数)在  System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(obj对象,  [对象]参数,对象[]参数)在  System.Reflection.RuntimeMethodInfo.Invoke(obj对象,的BindingFlags  invokeAttr,粘合剂粘合,对象[]参数,CultureInfo的文化)  在  Owin.Loader.DefaultLoader&LT;> c__DisplayClass12.b__b(IAppBuilder  建造者)在  Owin.Loader.DefaultLoader&LT;> c__DisplayClass1.b__0(IAppBuilder  建造者)在  Microsoft.Owin.Host.SystemWeb.OwinHttpModule&LT;> c__DisplayClass2.b__0(IAppBuilder  建造者)在  Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(动作 1  启动)在Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(动作 1  启动),在  Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint()在  System.Threading.LazyInitializer.EnsureInitializedCore [T](T&安培;目标,  布尔和放大器;初始化,对象和放大器; SYNCLOCK,Func键 1 valueFactory)在  Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication的  上下文)在  System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr的  appContext,HttpContext的背景下,MethodInfo的[]处理程序)在  System.Web.HttpApplication.InitSpecial(对HttpApplicationState状态,  MethodInfo的[]处理器,IntPtr的appContext,HttpContext的背景下),在  System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr的  appContext,HttpContext的背景下),在  System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr的  appContext)无法加载文件或程序集Microsoft.Owin.Security,  版本= 2.0.0.0,文化=中性公钥= 31bf3856ad364e35或  它的一个依赖。找到的程序集清单定义  不匹配的程序集引用。 (从HRESULT异常:  0x80131040)在  Owin.AppBuilderExtensions.UseExternalSignInCookie(IAp​​pBuilder应用程序,  字符串externalAuthenticationType)在  MySiteOnline.Startup.ConfigureAuth(IAppBuilder应用程序)的  C:\用户\安德烈\ Dropbox的\麦芽IT \活动  项目\ MySiteOnline \ MySiteOnline \ App_Start \ Startup.Auth.cs:行20  在MySiteOnline.Startup.Configuration(IAppBuilder应用程序)的  C:\用户\安德烈\ Dropbox的\麦芽IT \有效条件  System.RuntimeMethodHandle.InvokeMethod(对象的目标,对象[]  参数,签名的签名,布尔构造函数)在  System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(obj对象,  [对象]参数,对象[]参数)在  System.Reflection.RuntimeMethodInfo.Invoke(obj对象,的BindingFlags  invokeAttr,粘合剂粘合,对象[]参数,CultureInfo的文化)  在  Owin.Loader.DefaultLoader&LT;&GT;。c__DisplayClass12&LT; MakeDelegate&GT; b__b(IAppBuilder  建造者)在  Owin.Loader.DefaultLoader&LT;&GT;。c__DisplayClass1&LT; LoadImplementation&GT; b__0(IAppBuilder  建造者)在  Microsoft.Owin.Host.SystemWeb.OwinHttpModule.<>c__DisplayClass2.<InitializeBlueprint>b__0(IAppBuilder  建造者)在  Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(动作 1  启动)在Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(动作 1  启动),在  Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint()在  System.Threading.LazyInitializer.EnsureInitializedCore [T](T&安培;目标,  布尔和放大器;初始化,对象和放大器; SYNCLOCK,Func键 1 valueFactory)在  Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication的  上下文)在  System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr的  appContext,HttpContext的背景下,MethodInfo的[]处理程序)在  System.Web.HttpApplication.InitSpecial(对HttpApplicationState状态,  MethodInfo的[]处理器,IntPtr的appContext,HttpContext的背景下),在  System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr的  appContext,HttpContext的背景下),在  System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr的  appContext)

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.应用程序日志包含在我的硬盘驱动器/收存箱文件夹的引用文件。这是没有意义的,因为这是云计算的部署中运行!2.出于某种原因不明对我来说,应用程序试图加载Microsoft.Owin.Security版本2.0.0装配,虽然我已经在我的项目复制本地=真正的安装2.1.0.0版本。我也更新了我在web.config中集绑定如下:

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>

按照上面的堆栈跟踪,这里是code而导致的错误被抛出:

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.

我觉得我的脑海里可能会被打破试图解决这个难题。我也试过在清单文件中挖四周,涉足了不同的NuGet版本,但可惜......没有成功。

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.

推荐答案

这似乎与项目/清单文件被损坏,由于与版本控制问题的问题。我的假设是,事件的顺序如下搞砸的事情了:

It seems the problem related to project / manifest files being corrupted due to issues with versions control. My hypothesis is that the following sequence of events messed thing up:

  1. 更​​新了几个的NuGet包

  1. Updated a couple of Nuget packages

推code源代码管理。

Pushed code to Source Control.

恢复code,从源头控制previous版本。

Restored code to a previous version from source control.

我相信冥冥中这个过程中配置中/清单/ DLL文件未以一致的方式处理,导致clusterbeep我了。

I believe that somewhere during this process config/manifest/dll files were not handled in a consistent fashion and lead to the clusterbeep I had.

我的解决办法是恢复到我的项目的早期,工作版本和随后手动合并codechanges到(使用的WinMerge)的解决方案。

My solution was to revert to an earlier, working version of my project and to subsequently manually merge codechanges into the solution (using WinMerge).

虽然痛苦和耗时的工作,这似乎已经解决了所有的问题。

Although a painful and time-consuming activity, this seems to have resolved all of the problems.

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

  1. Enable "Wanrings" in your Error List window.

设置生成的输出冗长详细。在VS2013中,转到工具>选项>项目和解决方案>生成和运行。在设置MSBuild项目BUIL输出详细程度为详细的选项。检查编译后的输出的任何冲突,因为这也将指出正是冲突的程序集的位置。 (在解决方案中的项目被分配一个号码,与每个项目的操作相应标记,这个数字)。

Set build output verbosity to "Detailed". In VS2013, go to Tools > Options > Projects and Solutions > Build and Run. The set the option for "MSBuild project buil output verbosity" to "Detailed". Examine the output after build for any conflicts as this will also point out exactly where conflicting assemblies are located. (Projects in your solution are assigned a number and actions relating to each project is tagged accordingly with that number).

设置详细的应用程序日志为您的网站在Azure上。为此,选择从Azure管理门户网站,点击配置,浏览到应用程序诊断

Set up detailed application logging for your website on Azure. To do this select your site from the Azure management portal, click "Configure", browse down to "Application Diagnostics"

这篇关于Azure的Eventlogs - TargetInvocationException和怪异的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 07:53