Options

Profiler crashes when using Unity 1.2 application block

I am presently using ANTS 5.2.0.26 to profile two applications - both run as a console and both use Unity 1.2. However, the simpler of the two crashes immediately when loaded under the profiler (and only when loaded under the profiler) with this error:

Message
eFatalProgramFault {"Bad unmanaged code entry point.":"<Module>"} System.Exception {System.TypeLoadException}

Stack
at Microsoft.Practices.Unity.UnityContainer..ctor()

To illustrate this problem I created a simple test application that manifests the exact same failure when hosted under the profiler:

class Program
{
static void Main(string[] args)
{
try
{
UnityContainer unity = new UnityContainer();
}
catch(Exception eFatalProgramFault)
{
Console.WriteLine("Fatal exception:");
Console.WriteLine("Message
{0}{1}",Environment.NewLine, eFatalProgramFault.Message);
Console.WriteLine("Stack
{0}{1}",Environment.NewLine, eFatalProgramFault.StackTrace);
}
}
}

Unfortunately I do not receive any more detail nor do I receive an inner exception. I don’t understand why my substantially more complicated console (which uses the System.AddIn.Pipeline builder strategy) sails through this problem with aplomb and yet the simple example above implodes. Any opinions or advice would be much appreciated.

Thank you.

Comments

  • Options
    Thanks for the information - I can see that you have taken the time to filter the important info. Could you expalin any differences between the two applications - is there any difference in the *way* that Unity is used, for example?
  • Options
    And, do you like the late, great Douglas Adams by any chance? :)
  • Options
    Have you built in debug mode? Can you try a release build? Sometimes a badly-formatted pdb can get in the way of a profiling session.
  • Options
    Chris, thanks for your reply. Us Douglas Adams fans have to stick together ; )

    This problem appears in both debug and release mode. It only seems to occur when you choose “Line-level and method-level timings”, which sadly is what I need. The fact that one of my consoles works perfectly and one fails is baffling, considering that the simpler of the two manifests the problem (wouldn’t you think that the complex one would be more likely to break LOL).

    I don’t believe this is caused by a corrupt PDB since I was able to readily reproduce the problem in a new project by creating a simple wizarded console using the C# code I showed in the first post there, and as I mentioned it still happens in both debug and release.

    I’m using Visual Studio 2008 SP1 to build the project(s) on and x64 machine, all assemblies configured for “Any CPU” - and even on the off chance that the pre-built Unity assemblies might be the problem I downloaded the source and built them myself – even when I build the project with the actual unity source, attach to the project with a debugger when it’s loaded by ANTS but before the Unity .ctor and then attempt to step into the Unity .ctor “UnityContainer unity = new UnityContainer();” it crashes immediately with:

    System.TypeLoadException occurred
    Message="Bad unmanaged code entry point."
    Source="Microsoft.Practices.Unity"
    TypeName="<Module>"
    StackTrace:
    at Microsoft.Practices.Unity.UnityContainer..ctor()
    at UnityUnderANTS.Program.Main(String[] args) in C:\Temp\UnityUnderANTS\UnityUnderANTS\Program.cs:line 16
    InnerException:

    I have carefully examined the build settings for the unity assemblies and they look like entirely typical pedestrian assemblies to me. If you run that sample project I posted under the debugger only and look at the loaded modules in the debugger here’s what it lists:

    - Mscorlib.dll
    - UnityUnderANTS.exe
    - Microsoft.Practices.Unity.dll
    - Microsoft.Practices.ObjectBuilder2.dll

    Again this doesn’t look especially fishy to me. I can even force the Unity assemblies to load first as follows:

    Assembly.Load(AssemblyName.GetAssemblyName(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Microsoft.Practices.Unity.dll")));
    Assembly.Load(AssemblyName.GetAssemblyName(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Microsoft.Practices.ObjectBuilder2.dll")));

    This works fine, even under ANTS - until I try to new up Unity, and then it still crashes as before. Finally, if I attach to the project with a debugger when it’s loaded by ANTS but before the .ctor and then set breakpoints both in the Unity .ctor and its base I don’t hit those breakpoints – it’s like something lower level is crashing me.

    As to your other question, I don’t use Unity in any different *way* between either of my console applications – they both allocate a container using ‘new’ as shown above. One big endemic difference though is that the ‘working’ scenario uses the .NET Application Extensibility namespace (described here http://msdn.microsoft.com/en-us/magazine/cc163476.aspx). Each AddIn loaded in my pipeline builder still ‘news up’ a Unity container though. Clearly something about the context in which my AddIn is called by the pipeline builder is serendipitously making this work.

    I did try one last experiment of creating a new AppDomain and then allocating my unity container inside a new AppDomain (as that’s what happens with the pipeline builder) but that did not work either – so something else about the pipeline builder is magic besides its use of AppDomains.
  • Options
    Chris, I think the mystery is partially solved, though the solution is not clear. I am running on x64 Windows 7. If I compile my executable in 'x64' or 'Any CPU' then it crashes when loaded under ANTS and touches the Unity .ctor. If I compile my executable in 'x86' it works under ANTS. This seems to be the case regardless of whether I compile Unity 'Any CPU' or x86 specific, and only seems to pertain what platform the executable was compiled to.

    So I believe my other console was working accidentally because it was compiled with 'Mixed Platforms', and in fact has nothing to do with the pipeline builder.

    So now that I know about this problem, what is the solution? I did not knowingly install an x86-only version of ANTS. It does appear to have installed under the native 'C:\Program Files', as opposed to 'C:\Program Files (x86)'. When I run the profiler I see "RedGate.Profiler.UI.exe" without the splat "*" suggesting it is running x64 native, and when I run my test program again I see "UnityUnderANTS.exe" without the splat "*" (however if I run "UnityUnderANTS.exe" compiled to x86 then of course the process is listed with a splat "*", indicating it really is running in the 32-bit WOW).

    Finally, I see ANTS knows something about x64 since it has an x64 folder:

    C:\Program Files\Red Gate\ANTS Performance Profiler 5\X64

    It is, unfortunately, not a good solution for me to force my 64-bit application to 32-bit. Any thoughts on how to help ANTS along in this regard?

    Thanks!
  • Options
    When you do get errors - does anything interesting end up in the ANTS logs:


    %userprofile%\Local Settings\Application Data\Red Gate\ANTS Performance Profiler 5

    ANTS does run as native x64 here. Is your application targetted for CLR 4.0? If so, I think we're looking at a new issue. I would expect any x64 app, targeted for anything other than 4.0, to work fine (but since CLR 4.0 is so new- I would not be surprised at the odd crash like this).

    You may find the new version works better in this particular case:

    http://downloads.red-gate.com//EAP/ANTS ... .0.587.exe

    If this is not accurate, we would be happy to analyse a mini-dump.

    You may even find a re-install of ANTS helps.
  • Options
    If I run the x86 (working) case the ANTS log is as follows:

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    19 Jan 2010 12:35:43.327 [1] INFO RedGate.Profiler.Logging.LogService - Starting new ANTS Performance Profiler 5 session
    19 Jan 2010 12:35:43.342 [1] INFO RedGate.Profiler.Logging.LogService - Assembly version: 5.2.0.26
    19 Jan 2010 12:35:44.949 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - Exception whilst loading PerformanceProfilerSettings.xml...
    19 Jan 2010 12:35:44.949 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - Could not find file 'C:\Users\emily.lewis\AppData\Local\Red Gate\ANTS Performance Profiler 5\PerformanceProfilerSettings.xml'.
    19 Jan 2010 12:35:44.949 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - System.IO.FileNotFoundException
    19 Jan 2010 12:35:44.949 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
    at RedGate.Profiler.XmlPersist.XmlObjectLoader.Load(String filename)
    at RedGate.Profiler.Settings.PerformanceProfilerSettings.a()
    19 Jan 2010 12:35:49.520 [1] WARN RedGate.Profiler.OS.Local.LocalWindowsVersionInspector - Detected Windows version: Windows Vista Enterprise (6.1 64-bit)
    19 Jan 2010 12:35:49.520 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - IIS is supported on installed OS version
    19 Jan 2010 12:35:49.551 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Result of check to see if inetinfo.exe running: False
    19 Jan 2010 12:35:49.660 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Result of check to see if W3SVC running: False
    19 Jan 2010 12:35:49.660 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checks suggest that IIS does not appear to be running.
    19 Jan 2010 12:35:49.660 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checking for existence of inetinfo.exe at 'C:\Windows\system32\inetsrv\inetinfo.exe'
    19 Jan 2010 12:35:49.660 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Unable to find inetinfo.exe
    19 Jan 2010 12:35:49.676 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Result of check to see if W3SVC running: False
    19 Jan 2010 12:35:49.676 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checks confirm that IIS is not enabled.
    19 Jan 2010 12:35:49.676 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Successfully detected IIS installation: IIS 7 (Auto-detected) (Not verified) (Disabled)
    19 Jan 2010 12:35:49.676 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checks confirm that IIS is not installed.
    19 Jan 2010 12:35:58.740 [Profiler pipe monitor] WARN RedGate.Profiler.Engine.Startup.Basic.PipeConnection - Pipe has been closed; most likely the process being profiled has terminated.
    19 Jan 2010 12:35:58.911 [ConfigurableThreadPool thread] WARN RedGate.Profiler.Engine.Reports.Basic.ProfileRange - Range has a tick rate of 2415531.77881818KHz with a standard deviation of 71412.3877491724KHz. The deviance in clock speed seems high and may be causing a synchronisation issue.
    19 Jan 2010 12:35:59.301 [ConfigurableThreadPool thread] WARN RedGate.Profiler.Engine.Reports.Basic.ProfileRange - Range has a tick rate of 2415531.77881818KHz with a standard deviation of 71412.3877491724KHz. The deviance in clock speed seems high and may be causing a synchronisation issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



    If I run the x64 (failing) case the ANTS log is as follows:

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    19 Jan 2010 12:37:24.744 [1] INFO RedGate.Profiler.Logging.LogService - Starting new ANTS Performance Profiler 5 session
    19 Jan 2010 12:37:24.760 [1] INFO RedGate.Profiler.Logging.LogService - Assembly version: 5.2.0.26
    19 Jan 2010 12:37:26.335 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - Exception whilst loading PerformanceProfilerSettings.xml...
    19 Jan 2010 12:37:26.335 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - Could not find file 'C:\Users\emily.lewis\AppData\Local\Red Gate\ANTS Performance Profiler 5\PerformanceProfilerSettings.xml'.
    19 Jan 2010 12:37:26.335 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - System.IO.FileNotFoundException
    19 Jan 2010 12:37:26.351 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
    at RedGate.Profiler.XmlPersist.XmlObjectLoader.Load(String filename)
    at RedGate.Profiler.Settings.PerformanceProfilerSettings.a()
    19 Jan 2010 12:37:30.594 [1] WARN RedGate.Profiler.OS.Local.LocalWindowsVersionInspector - Detected Windows version: Windows Vista Enterprise (6.1 64-bit)
    19 Jan 2010 12:37:30.594 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - IIS is supported on installed OS version
    19 Jan 2010 12:37:30.610 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Result of check to see if inetinfo.exe running: False
    19 Jan 2010 12:37:30.735 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Result of check to see if W3SVC running: False
    19 Jan 2010 12:37:30.735 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checks suggest that IIS does not appear to be running.
    19 Jan 2010 12:37:30.735 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checking for existence of inetinfo.exe at 'C:\Windows\system32\inetsrv\inetinfo.exe'
    19 Jan 2010 12:37:30.735 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Unable to find inetinfo.exe
    19 Jan 2010 12:37:30.735 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Result of check to see if W3SVC running: False
    19 Jan 2010 12:37:30.735 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checks confirm that IIS is not enabled.
    19 Jan 2010 12:37:30.735 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Successfully detected IIS installation: IIS 7 (Auto-detected) (Not verified) (Disabled)
    19 Jan 2010 12:37:30.735 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checks confirm that IIS is not installed.
    19 Jan 2010 12:37:41.686 [ConfigurableThreadPool thread] WARN RedGate.Profiler.Engine.Reports.Basic.ProfileRange - Range has a tick rate of 2497061.08575KHz with a standard deviation of 55962.5483809925KHz. The deviance in clock speed seems high and may be causing a synchronisation issue.
    19 Jan 2010 12:37:42.076 [ConfigurableThreadPool thread] WARN RedGate.Profiler.Engine.Reports.Basic.ProfileRange - Range has a tick rate of 2497061.08575KHz with a standard deviation of 55962.5483809925KHz. The deviance in clock speed seems high and may be causing a synchronisation issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    The target executable is targeting .NET Framework 3.5, I haven’t made it around to playing with 4.0 yet ;o)

    I would be happy to capture the mini-dump or even upload the offending Visual Studio project if that would help. If you prefer the dump please let me know how to gather that and I will do so.

    In the mean time I installed and ran 6.0.0.587 of the profiler and observed the same crashing issue. Here is the log file:


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    19 Jan 2010 12:54:25.913 [1] INFO RedGate.Profiler.Logging.LogService - Starting new ANTS Performance Profiler 6 session
    19 Jan 2010 12:54:25.944 [1] INFO RedGate.Profiler.Logging.LogService - Assembly version: 6.0.0.587
    19 Jan 2010 12:54:28.144 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - Exception whilst loading PerformanceProfilerSettings.xml...
    19 Jan 2010 12:54:28.144 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - Could not find file 'C:\Users\emily.lewis\AppData\Local\Red Gate\ANTS Performance Profiler 6\PerformanceProfilerSettings.xml'.
    19 Jan 2010 12:54:28.144 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - System.IO.FileNotFoundException
    19 Jan 2010 12:54:28.160 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - at RedGate.Profiler.XmlPersist.XmlObjectLoader.Load(String filename)
    at (Object , String )
    at RedGate.Profiler.Settings.PerformanceProfilerSettings. ()
    19 Jan 2010 12:54:28.160 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - Caused by:
    19 Jan 2010 12:54:28.160 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - SmartExceptionsCore.UnhandledException @ 1081, offset:44
    19 Jan 2010 12:54:28.160 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings - SmartAssembly.SmartExceptionsCore.UnhandledException
    19 Jan 2010 12:54:28.160 [1] WARN RedGate.Profiler.Settings.PerformanceProfilerSettings -
    19 Jan 2010 12:54:32.224 [1] WARN RedGate.Profiler.OS.Local.LocalWindowsVersionInspector - Detected Windows version: Windows Vista Enterprise (6.1 64-bit)
    19 Jan 2010 12:54:32.224 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - IIS is supported on installed OS version
    19 Jan 2010 12:54:32.239 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Result of check to see if inetinfo.exe running: False
    19 Jan 2010 12:54:32.770 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Result of check to see if W3SVC running: False
    19 Jan 2010 12:54:32.770 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checks suggest that IIS does not appear to be running.
    19 Jan 2010 12:54:32.770 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checking for existence of inetinfo.exe at 'C:\Windows\system32\inetsrv\inetinfo.exe'
    19 Jan 2010 12:54:32.770 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Unable to find inetinfo.exe
    19 Jan 2010 12:54:32.785 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Result of check to see if W3SVC running: False
    19 Jan 2010 12:54:32.785 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checks confirm that IIS is not enabled.
    19 Jan 2010 12:54:32.785 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Successfully detected IIS installation: IIS 7 (Auto-detected) (Not verified) (Disabled)
    19 Jan 2010 12:54:32.785 [1] WARN RedGate.Profiler.IISSupport.Local.LocalIisInspector - Checks confirm that IIS is not installed.
    19 Jan 2010 12:54:42.309 [Profiler pipe monitor] WARN RedGate.Profiler.Engine.Startup.Basic.PipeConnection - Pipe has been closed; most likely the process being profiled has terminated.
    19 Jan 2010 12:54:42.636 [ConfigurableThreadPool thread] WARN RedGate.Profiler.Engine.Reports.Basic.ProfileRange - Range has a tick rate of 2564624.7842KHz with a standard deviation of 54745.7129991631KHz. The deviance in clock speed seems high and may be causing a synchronisation issue.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • Options
    Ok, we have something that often helps to make obtaining a mini-dump automatic:
    ftp://support.red-gate.com/utilities/AutoDumper.zip

    Extract all files to a directory

    Run

    Cscript adplus.vbs -crash -pn <name of process>

    If more than one process exists by the same name, you can use -P <pid> instead of -pn

    This then dumps large files to disk on a crash or hang trigger.

    I can allocate some ftp space if the files are large.
  • Options
    Just to confirm- I am convinced that "Bad unmanaged code entry point" means - ANTS does not like at least one of the pdbs (and one workaround is to delete all pdbs in the directory of the executable). This may be our bug, it may not be- we'll investigate. I acknowledge the very least we could do is deliver a more helpful error message...
Sign In or Register to comment.