Compartilhar via


QIK Wizard throws an exception, what to do?

Being excited by the elegance of .NET based Integration Pack architecture and simplicity of writing such an IP, today my colleague decided to write his own “Hello World”.  It didn’t take too long to get a DLL, and the next step is to package it to an OIP file.  Then he found that QIK Wizard threw the following exception:

image

Obviously the error message wasn’t helpful because it didn’t say what the exception really was, and how to resolve it.  In this case, windbg is our friend.  With SOS extension, windbg can tell us exactly what is happening and where the problem is.

Install windbg

For folks inside Microsoft, the latest internal version of windbg can be installed from the network share (contact me for more information).  For external people, you may need to install Windows SDK to get windbg at https://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx.  Some time ago, there was a separate download package for windbg.  Maybe someone can try https://msdn.microsoft.com/en-us/windows/hardware/gg463016 and see if it works.

Attach QIK Wizard process to windbg

Run C:\Debuggers32\windbg.exe and press F6 to attach a process:

image

Select QIKWizard.exe and click OK button.  Now the process breaks into the debugger.  QIK Wizard is a managed process and that exception is a CLR exception, so we want to catch the CLR exception:

0:008> sxe clr

Then press F5 to resume the process.  Reload the same DLL, this time the exception is caught by windbg:

image

Note the message in the command window also shows which DLL’s have been loaded.  In order to check the CLR exception, we need to load SOS extension:

0:000> .loadby sos mscorwks

Then print the current CLR exception and managed stack:

0:000> !sos.PrintException
Exception object: 02856d1c
Exception type: System.BadImageFormatException
Message: Could not load file or assembly 'file:///C:\Users\zhyao\Desktop\SampleIpP.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
InnerException: <none>
StackTrace (generated):
<none>
StackTraceString: <none>
HResult: 8013101b
0:000> !sos.CLRStack
OS Thread Id: 0x1378 (0)
ESP EIP
003cdb90 7492b727 [HelperMethodFrame_PROTECTOBJ: 003cdb90] System.Reflection.Assembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.Assembly, System.Threading.StackCrawlMark ByRef, Boolean, Boolean)
003cdc28 5e5e123c System.Reflection.Assembly.nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.Assembly, System.Threading.StackCrawlMark ByRef, Boolean, Boolean)
003cdc50 5e5dfc50 System.Reflection.Assembly.InternalLoad(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Threading.StackCrawlMark ByRef, Boolean)
003cdc78 5e55a6a4 System.Reflection.Assembly.InternalLoadFrom(System.String, System.Security.Policy.Evidence, Byte[], System.Configuration.Assemblies.AssemblyHashAlgorithm, Boolean, System.Threading.StackCrawlMark ByRef)
003cdc98 5e55a641 System.Reflection.Assembly.LoadFrom(System.String)
003cdca4 0043d761 Opalis.QuickIntegrationKit.Framework.Core.DomainManager.LoadAssembly(System.String)
003cdcd4 0043d719 Opalis.QuickIntegrationKit.Framework.Core.DomainManager.FindObjectTypes(System.String)
003cdcdc 0043d65e Opalis.QuickIntegrationKit.Framework.RequestBroker.GetObjectTypesFrom(System.String)
003cdf10 5f8d6678 [GCFrame: 003cdf10]
003ce06c 5f8d6678 [ComMethodFrame: 003ce06c]
003ce198 5f8d6678 [NDirectMethodFrameStandalone: 003ce198] Opalis.QIK.Wizard.Domain.Utility.StandardLibraryExplorer.getNumServices(System.String)
003ce1a8 0043cac5 Opalis.QIK.Wizard.Domain.Utility.StandardLibraryExplorer.DoGetServices(System.String)
003ce1ec 0043c9d0 Opalis.QIK.Wizard.Domain.Utility.LibraryExplorer.GetServices(System.String)
003ce1f4 0043d50e Opalis.QIK.Wizard.Presentation.ObjectPresenter.GetServices(Opalis.QIK.Wizard.Views.IObjectView, System.String)
003ce22c 0043d461 Opalis.QIK.Wizard.Presentation.ObjectPresenter.LibrarySelected(System.Object, Opalis.QIK.Wizard.Views.FileEventArgs)
003ce244 0043d3ed Opalis.QIK.Wizard.OpenFileView.ShowView()
003ce258 0043d238 Opalis.QIK.Wizard.Presentation.ObjectPresenter.SelectLibrary(System.Object, System.EventArgs)
003ce270 0043d1b6 Opalis.QIK.Wizard.ObjectTypeForm.BrowseLibraryButton_Click(System.Object, System.EventArgs)
003ce280 5d064170 System.Windows.Forms.Control.OnClick(System.EventArgs)
003ce298 5d05f55a System.Windows.Forms.Button.OnClick(System.EventArgs)
003ce2a8 5d5f6f24 System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs)
003ce2c4 5d5c7733 System.Windows.Forms.Control.WmMouseUp(System.Windows.Forms.Message ByRef, System.Windows.Forms.MouseButtons, Int32)
003ce350 5d8fa152 System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
003ce354 5d8f8921 [InlinedCallFrame: 003ce354]
003ce3ec 5d0925b0 System.Windows.Forms.Button.WndProc(System.Windows.Forms.Message ByRef)
003ce3f8 5d0986a0 System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
003ce400 5d098621 System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
003ce414 5d0984fa System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
003ce5b8 0014113c [NDirectMethodFrameStandalone: 003ce5b8] System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef)
003ce5c8 5d0a8cee System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32, Int32, Int32)
003ce664 5d0a8957 System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
003ce6b8 5d0a87a1 System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
003ce6e8 5d5bde2b System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form)
003ce6fc 5d5f2608 System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window)
003ce788 5d5f281f System.Windows.Forms.Form.ShowDialog()
003ce78c 0043ce25 Opalis.QIK.Wizard.ObjectTypeForm.ShowView()
003ce790 0043b07f Opalis.QIK.Wizard.Presentation.ObjectsPresenter.AddObject(System.Object, System.EventArgs)
003ce7ac 0043afcd Opalis.QIK.Wizard.ObjectTypesStep.FireAddObject()
003ce7b8 0043af8d Opalis.QIK.Wizard.ObjectTypesStep.AddButton_Click(System.Object, System.EventArgs)
003ce7c0 5d064170 System.Windows.Forms.Control.OnClick(System.EventArgs)
003ce7d8 5d05f55a System.Windows.Forms.Button.OnClick(System.EventArgs)
003ce7e8 5d5f6f24 System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs)
003ce804 5d5c7733 System.Windows.Forms.Control.WmMouseUp(System.Windows.Forms.Message ByRef, System.Windows.Forms.MouseButtons, Int32)
003ce890 5d8fa152 System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
003ce894 5d8f8921 [InlinedCallFrame: 003ce894]
003ce92c 5d0925b0 System.Windows.Forms.Button.WndProc(System.Windows.Forms.Message ByRef)
003ce938 5d0986a0 System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
003ce940 5d098621 System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
003ce954 5d0984fa System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
003ceaf8 0014113c [NDirectMethodFrameStandalone: 003ceaf8] System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef)
003ceb08 5d0a8cee System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32, Int32, Int32)
003ceba4 5d0a8957 System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
003cebf8 5d0a87a1 System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
003cec28 5d065911 System.Windows.Forms.Application.Run(System.Windows.Forms.Form)
003cec3c 00430093 Opalis.QIK.Wizard.QuickIntegrationWizard.Main()
003cee64 5f7b1b4c [GCFrame: 003cee64]

From the exception message, it is clear that the CLR version of the DLL being loaded is newer than the CLR version of QIKWizard.  Since QIKWizard uses .NET 3.5 which is CLR2, it means the DLL is actually built with CLR4.  After changing the .NET framework version, the problem is solved.

Note that this debugging process does not need any symbols or Opalis source code.  We do not even need to access public Microsoft symbol server.

Windbg with SOS extension can do many useful things.  For more information on SOS, read MSDN documentation at https://msdn.microsoft.com/en-us/library/bb190764.aspx.  Later I will show you more simple tricks to troubleshoot Opalis issues.

Comments

  • Anonymous
    June 16, 2011
    Your article is nice! I love it.Thanks for you sharing.