locked
FolderBrowserDialog and P/Invoke shlwapi PathCombine cause RtlHeap corruption RRS feed

  • Question

  • Hello,
    The following sample code causes heap corruption int 3 thrown from RtlFreeHeap.
    Executing FolderBrowserDialog.ShowDialog() and P/Invoke shlwapi PathCombine() after eachother causes the problem.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace TestFolderBrowserDialog
    {
      public partial class FrmTestFolderBrowserDialog : Form
      {
        public FrmTestFolderBrowserDialog()
        {
          InitializeComponent();
        }

        //---------------------------------------------------------------------------

        private void btnTestFolderBrowserDialog_Click(object sender, EventArgs e)
        {
          TestFolderBrowserDialog();
        }

        //---------------------------------------------------------------------------

        [DllImport("kernel32.dll")]
        static extern uint GetCurrentDirectory(uint nBufferLength, [Out] StringBuilder lpBuffer);

        [DllImport("shlwapi.dll", CharSet = CharSet.Auto)]
        static extern string PathCombine([Out] StringBuilder lpszDest, string lpszDir, string lpszFile);

        private void TestFolderBrowserDialog()
        {
          const string sMyFunc = "TestFolderBrowserDialog";
          StringBuilder fullDirFileName;
          FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
          bool bShowFolderBrowserDialog = true;
          folderBrowserDialog.SelectedPath = Directory.GetCurrentDirectory();
          if (bShowFolderBrowserDialog) {
            folderBrowserDialog.ShowDialog();
          }
          fullDirFileName = new StringBuilder(NativeMethods.MAX_PATH);
          NativeMethods.GetCurrentDirectory(NativeMethods.MAX_PATH, fullDirFileName);
          Trace.WriteLine(sMyFunc + ": After GetCurrentDirectory '" + fullDirFileName + "'");

          string sStartDir, sWildCards;
          sStartDir = folderBrowserDialog.SelectedPath;
          sWildCards = "*.*";
          fullDirFileName = new StringBuilder(NativeMethods.MAX_PATH);

          // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
          PathCombine(fullDirFileName, sStartDir, sWildCards);
          // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

          Trace.WriteLine(sMyFunc + ": After PathCombine '" + fullDirFileName + "'");
        }

      }
    }


    Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
    Copyright (c) Microsoft Corporation. All rights reserved.

    *** wait with pending attach
    WARNING: Inaccessible path: 'C:\user\svn\Trunk\Symbols'
    Symbol search path is: SRV*C:\user\svn\trunk\websymbols*http://msdl.microsoft.com/download/symbols;C:\user\svn\Trunk\Symbols;C:\User\VCSharp\TextSearch\TextSearch\bin\Debug
    Executable search path is:
    ModLoad: 01330000 0133a000   C:\User\VCSharp\TestCreateInstance\TestCreateInstance\bin\Debug\TestCreateInstance.exe
    ModLoad: 77af0000 77c17000   C:\Windows\system32\ntdll.dll
    ModLoad: 72670000 726ba000   C:\Windows\system32\mscoree.dll
    ModLoad: 77a10000 77aec000   C:\Windows\system32\KERNEL32.dll
    ModLoad: 773c0000 77486000   C:\Windows\system32\ADVAPI32.dll
    ModLoad: 76240000 76303000   C:\Windows\system32\RPCRT4.dll
    ModLoad: 72250000 722b6000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll
    ModLoad: 761a0000 761f9000   C:\Windows\system32\SHLWAPI.dll
    ModLoad: 76310000 7635b000   C:\Windows\system32\GDI32.dll
    ModLoad: 77970000 77a0d000   C:\Windows\system32\USER32.dll
    ModLoad: 77690000 7773a000   C:\Windows\system32\msvcrt.dll
    ModLoad: 77740000 7775e000   C:\Windows\system32\IMM32.DLL
    ModLoad: 778a0000 77968000   C:\Windows\system32\MSCTF.dll
    ModLoad: 76230000 76239000   C:\Windows\system32\LPK.DLL
    ModLoad: 77c30000 77cad000   C:\Windows\system32\USP10.dll
    ModLoad: 75fd0000 75ff3000   C:\PROGRA~1\GOOGLE\GOOGLE~1\GOEC62~1.DLL
    ModLoad: 76200000 7622d000   C:\Windows\system32\WS2_32.dll
    ModLoad: 77c20000 77c26000   C:\Windows\system32\NSI.dll
    ModLoad: 74eb0000 7504e000   C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6002.18305_none_5cb72f2a088b0ed3\comctl32.dll
    ModLoad: 551e0000 5584f000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
    ModLoad: 5bbb0000 5bc6e000   C:\Windows\system32\MSVCR100_CLR0400.dll
    ModLoad: 6bb20000 6bb2d000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\culture.dll
    ModLoad: 53640000 54403000   C:\Windows\assembly\NativeImages_v4.0.30319_32\mscorlib\4ff1f12a08d455f195ba996fe77497c6\mscorlib.ni.dll
    ModLoad: 774e0000 775c6000   C:\Windows\system32\WININET.dll
    ModLoad: 77d40000 77d43000   C:\Windows\system32\Normaliz.dll
    ModLoad: 77760000 77893000   C:\Windows\system32\urlmon.dll
    ModLoad: 76760000 768a5000   C:\Windows\system32\ole32.dll
    ModLoad: 775d0000 7765d000   C:\Windows\system32\OLEAUT32.dll
    ModLoad: 764f0000 766d9000   C:\Windows\system32\iertutil.dll
    ModLoad: 76030000 76044000   C:\Windows\system32\Secur32.dll
    ModLoad: 768b0000 773c0000   C:\Windows\system32\SHELL32.dll
    ModLoad: 75500000 7553b000   C:\Windows\system32\rsaenh.dll
    ModLoad: 751b0000 751ef000   C:\Windows\system32\uxtheme.dll
    ModLoad: 60d20000 60d88000   C:\PROGRAM FILES\NORTON INTERNET SECURITY\ENGINE\18.5.0.125\ASOEHOOK.DLL
    ModLoad: 73f00000 73f85000   C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.6002.18305_none_88f3a38569c2c436\COMCTL32.dll
    ModLoad: 726f0000 72793000   C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4974_none_50940634bcb759cb\MSVCR90.dll
    ModLoad: 727a0000 7282e000   C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4974_none_50940634bcb759cb\MSVCP90.dll
    ModLoad: 6bae0000 6baf0000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\nlssorting.dll
    ModLoad: 5cc40000 5cca0000   C:\Windows\Microsoft.NET\Framework\v4.0.30319\clrjit.dll
    ModLoad: 54940000 551d8000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System\161c6f80ad93b0505054d244f1c6243c\System.ni.dll
    ModLoad: 5aee0000 5b076000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Drawing\2fe09cc54a8390b20e380239db34228f\System.Drawing.ni.dll
    ModLoad: 51d60000 529cb000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Windows.Forms\f3cdd09fc0acc85c7febbd2e2ef9c4e5\System.Windows.Forms.ni.dll
    ModLoad: 578d0000 579c1000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Configuration\ac2cd19f2159d48684e17cbdecfaa3b7\System.Configuration.ni.dll
    ModLoad: 68960000 68eb3000   C:\Windows\assembly\NativeImages_v4.0.30319_32\System.Xml\2d7c29ad77c15abfa6a8fe6d24840a91\System.Xml.ni.dll
    ModLoad: 74960000 74b0b000   C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.0.6002.18005_none_9e50b396ca17ae07\gdiplus.dll
    ModLoad: 77cb0000 77d34000   C:\Windows\system32\CLBCatQ.DLL
    (189c.1cb4): Break instruction exception - code 80000003 (first chance)
    eax=7ffda000 ebx=00000000 ecx=00000000 edx=77b7c964 esi=00000000 edi=00000000
    eip=77b38b2e esp=058cfa18 ebp=058cfa44 iopl=0         nv up ei pl zr na pe nc
    cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
    ntdll!DbgBreakPoint:
    77b38b2e cc              int     3
    0:004> .load C:\Windows\Microsoft.NET\Framework\v4.0.30319\SOS.dll
    0:004> g
    ModLoad: 00e00000 00e3c000   MbBaseLib.dll
    ModLoad: 011c0000 011fc000   MbBaseLib.dll
    ModLoad: 715f0000 716f8000   C:\Windows\system32\shdocvw.dll
    ModLoad: 76050000 7606e000   C:\Windows\system32\USERENV.dll
    ModLoad: 74260000 74354000   C:\Windows\system32\WindowsCodecs.dll
    ModLoad: 75fa0000 75fcc000   C:\Windows\system32\apphelp.dll
    ModLoad: 70e80000 70e9f000   EhStorAPI.DLL
    ModLoad: 70e80000 70e9f000   C:\Windows\system32\EhStorShell.dll
    ModLoad: 74740000 747fb000   C:\Windows\system32\PROPSYS.dll
    ModLoad: 6fc00000 7000b000   GrooveEX.DLL
    ModLoad: 6fc00000 7000b000   C:\PROGRA~1\MICROS~3\Office14\GROOVEEX.DLL
    ModLoad: 70640000 7066b000   C:\Windows\WinSxS\x86_microsoft.vc90.atl_1fc8b3b9a1e18e3b_9.0.30729.4974_none_51cdc180bbe4500f\ATL90.DLL
    ModLoad: 6f3e0000 6f7ef000   C:\PROGRA~1\COMMON~1\MICROS~1\OFFICE14\Cultures\office.odf
    ModLoad: 6e2c0000 6eb49000   C:\PROGRA~1\MICROS~3\Office14\1031\GrooveIntlResource.dll
    ModLoad: 6f270000 6f305000   CSCUI.dll
    ModLoad: 714a0000 715e6000   C:\Windows\system32\browseui.dll
    ModLoad: 75180000 751b0000   C:\Windows\system32\DUser.dll
    ModLoad: 6f210000 6f270000   C:\Program Files\Common Files\microsoft shared\ink\tiptsf.dll
    ModLoad: 76360000 764ea000   C:\Windows\system32\SETUPAPI.dll
    ModLoad: 75ba0000 75bb4000   C:\Windows\system32\MPR.dll
    ModLoad: 73aa0000 73ab3000   C:\Windows\System32\ntlanman.dll
    ModLoad: 75d20000 75d96000   C:\Windows\System32\NETAPI32.dll
    ModLoad: 76100000 76107000   C:\Windows\system32\PSAPI.DLL
    ModLoad: 73b10000 73b18000   C:\Windows\System32\drprov.dll
    ModLoad: 73430000 73442000   C:\Windows\System32\davclnt.dll
    ModLoad: 75aa0000 75b92000   C:\Windows\System32\CRYPT32.dll
    ModLoad: 75c00000 75c12000   C:\Windows\System32\MSASN1.dll
    ModLoad: 73630000 7363b000   C:\Windows\system32\cscapi.dll
    ModLoad: 56630000 5689e000   SHMEDIA.dll
    ModLoad: 56630000 5689e000   C:\Windows\system32\wpdshext.dll
    ModLoad: 750a0000 750d2000   C:\Windows\system32\WINMM.dll
    ModLoad: 75060000 7509d000   C:\Windows\system32\OLEACC.dll
    ModLoad: 71830000 71886000   C:\Windows\system32\PortableDeviceApi.dll
    ModLoad: 6c930000 6cb53000   NetworkExplorer.dll
    ModLoad: 6c930000 6cb53000   C:\Windows\system32\NetworkExplorer.dll
    ModLoad: 74c00000 74c2d000   C:\Windows\system32\WINTRUST.dll
    ModLoad: 77660000 77689000   C:\Windows\system32\imagehlp.dll
    ModLoad: 70a30000 70a5b000   C:\Windows\system32\PortableDeviceTypes.dll
    ModLoad: 5b9f0000 5ba2f000   SHMEDIA.dll
    ModLoad: 5b9f0000 5ba2f000   C:\Windows\system32\audiodev.dll
    ModLoad: 706b0000 708fb000   C:\Windows\system32\WMVCore.DLL
    ModLoad: 70ad0000 70b09000   C:\Windows\system32\WMASF.DLL
    ModLoad: 74670000 74690000   C:\Windows\System32\EhStorAPI.dll
    ModLoad: 70e10000 70e5a000   C:\Windows\system32\ntshrui.dll
    ModLoad: 75a60000 75a9a000   C:\Windows\system32\slc.dll
    ModLoad: 75480000 754a1000   C:\Windows\system32\NTMARTA.DLL
    ModLoad: 77490000 774d9000   C:\Windows\system32\WLDAP32.dll
    ModLoad: 75c20000 75c31000   C:\Windows\system32\SAMLIB.dll
    TestFolderBrowserDialog: After GetCurrentDirectory 'C:\User\VCSharp\TestCreateInstance\TestCreateInstance\bin\Debug'
    Critical error detected c0000374
    (189c.1e88): Break instruction exception - code 80000003 (first chance)
    eax=00000000 ebx=00000000 ecx=77b27463 edx=0018e74d esi=00290000 edi=0602a4c8
    eip=77b38b2e esp=0018e99c ebp=0018ea18 iopl=0         nv up ei pl nz na pe nc
    cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000206
    ntdll!DbgBreakPoint:
    77b38b2e cc              int     3
    0:000> !dumpstack
    OS Thread Id: 0x1e88 (0)
    Current frame: ntdll!DbgBreakPoint
    ChildEBP RetAddr  Caller, Callee
    0018e998 77b9facb ntdll!RtlReportCriticalFailure+0x2e, calling ntdll!DbgBreakPoint
    0018e9c0 77afe794 ntdll!RtlWalkFrameChain+0x82, calling ntdll!_SEH_epilog4
    0018e9f4 77b1c92a ntdll!RtlUniform+0x28, calling ntdll!_aullrem
    0018ea18 77ba0704 ntdll!RtlpReportHeapFailure+0x21, calling ntdll!RtlReportCriticalFailure
    0018ea28 77ba07f2 ntdll!RtlpLogHeapFailure+0xa1, calling ntdll!RtlpHeapHandleError
    0018ea5c 77b5fc25 ntdll!RtlFreeHeap+0x60, calling ntdll!RtlpLogHeapFailure
    0018ea88 77a59a26 KERNEL32!HeapFree+0x14, calling ntdll!RtlFreeHeap
    0018ea9c 767bafbd ole32!CRetailMalloc_Free+0x1c, calling KERNEL32!HeapFree
    0018eab0 767bafd9 ole32!CoTaskMemFree+0x13
    0018eac0 538fe8f4 (MethodDesc 536c2e2c +0x34 DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr))
    0018eadc 538fe8f4 (MethodDesc 536c2e2c +0x34 DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr))
    0018eb08 00800c62 (MethodDesc 00218960 +0x312 DomainBoundILStubClass.IL_STUB_PInvoke(System.Text.StringBuilder, System.String, System.String)), calling 5381939c
    0018eb24 00800b4c (MethodDesc 00218960 +0x1fc DomainBoundILStubClass.IL_STUB_PInvoke(System.Text.StringBuilder, System.String, System.String))
    0018eb88 761bb3fb SHLWAPI!PathCombineW
    0018ebe4 00800636 (MethodDesc 002163d0 +0x136 TestCreateInstance.FrmTestCreateInstance.TestFolderBrowserDialog()), calling 0021c27c
    0018ec2c 008004e3 (MethodDesc 00216374 +0x23 TestCreateInstance.FrmTestCreateInstance.btnTestFolderBrowserDialog_Click(System.Object, System.EventArgs)), calling 0021c0c4
    0018ec3c 51f24ae8 (MethodDesc 51d7c1e8 +0x70 System.Windows.Forms.Control.OnClick(System.EventArgs))
    0018ec58 51f270a2 (MethodDesc 51e11900 +0xa2 System.Windows.Forms.Button.OnClick(System.EventArgs)), calling (MethodDesc 51d7c1e8 +0 System.Windows.Forms.Control.OnClick(System.EventArgs))
    0018ec70 524b6174 (MethodDesc 51e11918 +0xac System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs))
    0018ec8c 524895b5 (MethodDesc 51d7d764 +0x2d1 System.Windows.Forms.Control.WmMouseUp(System.Windows.Forms.Message ByRef, System.Windows.Forms.MouseButtons, Int32))
    0018ed18 5284a1bf (MethodDesc 51d7c940 System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)), calling 51efae94
    0018ed30 51f770f3 (MethodDesc 51e173c4 +0x13 System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef))
    0018ed38 51f77071 (MethodDesc 51e173cc +0x31 System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)), calling 00227346
    0018ed3c 51f77764 (MethodDesc 51d80a0c +0x14 System.Windows.Forms.NativeMethods.get_WM_UIUNSUBCLASS()), calling  (JitHelp: CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE)
    0018ed78 528518dd (MethodDesc 51e12274 System.Windows.Forms.ButtonBase.WndProc(System.Windows.Forms.Message ByRef)), calling (MethodDesc 51d7c940 +0 System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef))
    0018edbc 51f8de00 (MethodDesc 51e11948 +0x20 System.Windows.Forms.Button.WndProc(System.Windows.Forms.Message ByRef)), calling (MethodDesc 51e12274 +0 System.Windows.Forms.ButtonBase.WndProc(System.Windows.Forms.Message ByRef))
    0018edc8 51f770f3 (MethodDesc 51e173c4 +0x13 System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef))
    0018edd0 51f77071 (MethodDesc 51e173cc +0x31 System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)), calling 00227346
    0018ede4 51f76fb6 (MethodDesc 51d7eaec +0x96 System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr))
    0018ee38 00d609dd 00d609dd
    0018ee60 778a2501 MSCTF!TF_Notify+0x239, calling MSCTF!_SEH_epilog4
    0018ee6c 7798fd72 USER32!InternalCallWinProc+0x23
    0018ee98 7798fe4a USER32!UserCallWinProcCheckWow+0x14b, calling USER32!InternalCallWinProc
    0018eedc 7798fdf3 USER32!UserCallWinProcCheckWow+0x5c, calling ntdll!RtlActivateActivationContextUnsafeFast
    0018eee4 77989c78 USER32!CallHookWithSEH+0x47, calling USER32!_SEH_epilog4
    0018ef10 7799018d USER32!DispatchMessageWorker+0x322, calling USER32!UserCallWinProcCheckWow
    0018ef74 7799022b USER32!DispatchMessageW+0xf, calling USER32!DispatchMessageWorker
    0018ef84 51f92eec (MethodDesc 51d7f0c8 +0x3c DomainBoundILStubClass.IL_STUB_PInvoke(MSG ByRef))
    0018efa0 51f92eec (MethodDesc 51d7f0c8 +0x3c DomainBoundILStubClass.IL_STUB_PInvoke(MSG ByRef))
    0018efd0 51f871ff (MethodDesc 51d823c8 +0x287 System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)), calling 51ece234
    0018efe8 51f8737a (MethodDesc 51d823c8 +0x402 System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)), calling USER32!NtUserWaitMessage
    0018f064 51f86e2c (MethodDesc 51e1bb44 +0x16c System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)), calling 002274c2
    0018f0c0 51f86c81 (MethodDesc 51d80928 +0x61 System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)), calling (MethodDesc 51e1bb44 +0 System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext))
    0018f0f0 51f1366d (MethodDesc 51d7a8ec +0x31 System.Windows.Forms.Application.Run(System.Windows.Forms.Form)), calling 51ed0bb0
    0018f108 008000ae (MethodDesc 00213840 +0x3e TestCreateInstance.Program.Main()), calling (MethodDesc 51d7a8ec +0 System.Windows.Forms.Application.Run(System.Windows.Forms.Form))
    0018f114 551e21db clr!CallDescrWorker+0x33
    0018f124 55204a2a clr!CallDescrWorkerWithHandler+0x8e, calling clr!CallDescrWorker
    0018f178 551fc58d clr!ArgIterator::Init+0x6b, calling clr!MetaSig::HasRetBuffArg
    0018f1a0 55204bcc clr!MethodDesc::CallDescr+0x194, calling clr!CallDescrWorkerWithHandler
    0018f1cc 552028bb clr!MetaSig::MetaSig+0x3c, calling MSVCR100_CLR0400!memcpy
    0018f1dc 55204b0a clr!MethodDesc::CallDescr+0xa8, calling clr!ClrSafeInt<unsigned long>::addition
    0018f1e8 55204b1a clr!MethodDesc::CallDescr+0xb4, calling clr!_alloca_probe_16
    0018f258 551ee30a clr!MethodDesc::GetSigFromMetadata+0x21
    0018f298 55204aa5 clr!MethodDesc::CallDescr+0x21, calling clr!_alloca_probe_16
    0018f2dc 55204c01 clr!MethodDesc::CallTargetWorker+0x21, calling clr!MethodDesc::CallDescr
    0018f2f8 55204c21 clr!MethodDescCallSite::Call+0x1c, calling clr!MethodDesc::CallTargetWorker
    0018f310 552cce82 clr!ClassLoader::RunMain+0x24c, calling clr!MethodDescCallSite::CallWithValueTypes_RetArgSlot
    0018f410 551ee30a clr!MethodDesc::GetSigFromMetadata+0x21
    0018f474 552ccf90 clr!Assembly::ExecuteMainMethod+0xc1, calling clr!ClassLoader::RunMain
    0018f4a4 551e1ad1 clr!_EH_epilog3_GS+0xa, calling clr!__security_check_cookie
    0018f4a8 5523d804 clr!SString::ConvertToUnicode+0x8b, calling clr!_EH_epilog3_GS
    0018f4dc 551fcd88 clr!HardCodedMetaSig::GetBinarySig+0x130, calling clr!_EH_epilog3_GS
    0018f4e8 77b568fd ntdll!RtlpLowFragHeapAllocFromContext+0xa6f, calling ntdll!_SEH_epilog4
    0018f4ec 77b568fd ntdll!RtlpLowFragHeapAllocFromContext+0xa6f, calling ntdll!_SEH_epilog4
    0018f560 77b568fd ntdll!RtlpLowFragHeapAllocFromContext+0xa6f, calling ntdll!_SEH_epilog4
    0018f564 77b5661f ntdll!RtlAllocateHeap+0x17c, calling ntdll!RtlpLowFragHeapAllocFromContext
    0018f584 551e1c49 clr!UnsafeEELeaveCriticalSection+0xe, calling ntdll!RtlLeaveCriticalSection
    0018f588 551e1c5c clr!UnsafeEELeaveCriticalSection+0x21, calling  (JitHelp: CORINFO_HELP_GET_THREAD)
    0018f59c 55202cac clr!BaseDomain::AllocateObjRefPtrsInLargeTable+0xd9, calling clr!_EH_epilog3
    0018f5ac 55273952 clr!SetObjectReferenceUnchecked+0x63, calling clr!_EH_epilog3
    0018f5c8 77b566ea ntdll!RtlFreeHeap+0x101, calling ntdll!RtlpLowFragHeapFree
    0018f5e4 77b55620 ntdll!NtWaitForSingleObject+0xc
    0018f5e8 77a59884 KERNEL32!WaitForSingleObjectEx+0xbe, calling ntdll!NtWaitForSingleObject
    0018f5f4 77a598b4 KERNEL32!WaitForSingleObjectEx+0xf9, calling KERNEL32!_SEH_epilog4
    0018f610 77b566ea ntdll!RtlFreeHeap+0x101, calling ntdll!RtlpLowFragHeapFree
    0018f624 77a59a26 KERNEL32!HeapFree+0x14, calling ntdll!RtlFreeHeap
    0018f638 5523c036 clr!EEHeapFree+0x36, calling KERNEL32!HeapFree
    0018f64c 5523c09d clr!EEHeapFreeInProcessHeap+0x24, calling clr!EEHeapFree
    0018f660 5523bf4a clr!SaveLastErrorHolder::~SaveLastErrorHolder+0x16, calling KERNEL32!GetLastError
    0018f668 5523c07e clr!operator delete[]+0x41, calling clr!_EH_epilog3
    0018f690 5523c07e clr!operator delete[]+0x41, calling clr!_EH_epilog3
    0018f694 5533320a clr!AppDomain::SetFriendlyName+0x16c, calling clr!operator delete[]
    0018f698 55333210 clr!AppDomain::SetFriendlyName+0x172, calling clr!_EH_epilog3
    0018f6dc 552ccda4 clr!SystemDomain::ExecuteMainMethod+0x4ec, calling clr!Assembly::ExecuteMainMethod
    0018f7d4 77b57533 ntdll!RtlpFreeHeap+0xb40, calling ntdll!RtlLeaveCriticalSection
    0018f7dc 77b57512 ntdll!RtlpFreeHeap+0xb09, calling ntdll!_SEH_epilog4
    0018f880 77b31c5f ntdll!RtlpFreeDebugInfo+0x4b, calling ntdll!RtlInterlockedPushEntrySList
    0018f8c0 77b57512 ntdll!RtlpFreeHeap+0xb09, calling ntdll!_SEH_epilog4
    0018f8c4 77b57545 ntdll!RtlFreeHeap+0x14e, calling ntdll!RtlpFreeHeap
    0018f8e0 77a59a26 KERNEL32!HeapFree+0x14, calling ntdll!RtlFreeHeap
    0018f8ec 551e1d85 clr!UnsafeEETryEnterCriticalSection+0xf, calling ntdll!RtlTryEnterCriticalSection
    0018f8f0 551e1d9e clr!UnsafeEETryEnterCriticalSection+0x28, calling  (JitHelp: CORINFO_HELP_GET_THREAD)
    0018f8fc 551e1d55 clr!CrstBase::Enter+0xb4, calling clr!UnsafeEETryEnterCriticalSection
    0018f918 551e1bf3 clr!GCHolderBase<1,0,0,0>::Pop+0x20, calling clr!Thread::DisablePreemptiveGC
    0018f924 5523c345 clr!CrstBase::AcquirePreempLock+0x33, calling clr!_EH_epilog3
    0018f950 5523c345 clr!CrstBase::AcquirePreempLock+0x33, calling clr!_EH_epilog3
    0018f954 551e1ad1 clr!_EH_epilog3_GS+0xa, calling clr!__security_check_cookie
    0018f958 551fcd88 clr!HardCodedMetaSig::GetBinarySig+0x130, calling clr!_EH_epilog3_GS
    0018f970 551e1c49 clr!UnsafeEELeaveCriticalSection+0xe, calling ntdll!RtlLeaveCriticalSection
    0018f974 551e1c5c clr!UnsafeEELeaveCriticalSection+0x21, calling  (JitHelp: CORINFO_HELP_GET_THREAD)
    0018f97c 551e1c8f clr!CrstBase::Leave+0x2b, calling clr!UnsafeEELeaveCriticalSection
    0018f988 552032e6 clr!DomainLocalModule::SetClassFlags+0x81, calling clr!_EH_epilog3
    0018fa68 551e1b19 clr!_EH_epilog3_catch_GS+0xa, calling clr!__security_check_cookie
    0018fa6c 553363b9 clr!EEStartupHelper+0x9a3, calling clr!_EH_epilog3_catch_GS
    0018fa98 773e998b ADVAPI32!RegEnumValueW+0x308, calling ADVAPI32!_SEH_epilog4
    0018fb94 553363b9 clr!EEStartupHelper+0x9a3, calling clr!_EH_epilog3_catch_GS
    0018fb98 552cc496 clr!EEStartup+0x52, calling clr!EEStartupHelper
    0018fbc0 552cd199 clr!ExecuteEXE+0x58, calling clr!SystemDomain::ExecuteMainMethod
    0018fc14 552cd09a clr!_CorExeMainInternal+0x19f, calling clr!ExecuteEXE
    0018fc2c 72255011 mscoreei!BaseWrapper<ICLRRuntimeInfo *,FunctionBase<ICLRRuntimeInfo *,&DoNothing<ICLRRuntimeInfo *>,&DoTheRelease<ICLRRuntimeInfo>,2>,0,&CompareDefault<ICLRRuntimeInfo *>,2>::~BaseWrapper<ICLRRuntimeInfo *,FunctionBase<ICLRRuntimeInfo *,&DoNothing<ICLRRuntimeInfo *>,&DoTheRelease<ICLRRuntimeInfo>,2>,0,&CompareDefault<ICLRRuntimeInfo *>,2>+0x30, calling mscoreei!_EH_epilog3
    0018fc60 5534af00 clr!_CorExeMain+0x4e, calling clr!_CorExeMainInternal
    0018fc98 722555ab mscoreei!_CorExeMain+0x38
    0018fca4 72677f16 mscoree!ShellShim__CorExeMain+0x99
    0018fcb4 72674de3 mscoree!_CorExeMain_Exported+0x8, calling mscoree!ShellShim__CorExeMain
    0018fcbc 77a5d0e9 KERNEL32!BaseThreadInitThunk+0xe
    0018fcc8 77b319bb ntdll!__RtlUserThreadStart+0x23
    0018fd08 77b3198e ntdll!_RtlUserThreadStart+0x1b, calling ntdll!__RtlUserThreadStart


    Any ideas, what the problem could be?

    I also tried the folling without success:

    [DllImport("shlwapi.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr PathCombine(string lpszDir, string lpszFile);

    IntPtr iPtr;
    iPtr = PathCombine(sStartDir, sWildCards);
    sFullDirFileName = Marshal.PtrToStringAnsi(iPtr);

    Thanks & greetings marcel

     

    Saturday, January 29, 2011 11:11 AM

All replies

  • Hi Marcelloman,

    The problem is with the value of NativeMethods.MAX_PATH. This value for the buffer is too small to hold your 2 strings. Try giving some greater values say 2048 in place of NativeMethods.MAX_PATH. Then it should work fine.

    Regards,
    Adavesh

    -----------------------------

    Please mark the post as answered if it solved your problem. Happy programming !!!


     

    Sunday, January 30, 2011 4:01 AM
  • Hello Adavesh,
    I tried to increase the StringBuilder buffer size given to PathCombine without success.
    PathCombine() works fine without calling FolderBrowserDialog.ShowDialog() before.
    I forgot to mention that the problem arises on Windows XP Professional, on Windows Vista Ultimate and Windows 7 Professional with .NET Framework 2.0 and 4.0.
    On Windows XP the application hangs, on Vista and Windows 7 it terminates.
    I found the following post from JohnR with almost the same problem:
    http://bytes.com/topic/visual-basic-net/answers/387063-folderbrowserdialog-hangs-application
    He was not so lucky to be able to narrow down the problem so far that Microsoft payed attention to it.
    Greetings Marcel

    Monday, January 31, 2011 7:32 PM
  • Hello Adavesh,
    Thanks for your reply.
    I never new what to think about P/Invoke calls and garbage collection.
    Therefore I decided to build some test applications to do exactly those things the .NET Framework does not like and see what happens.
    The code above was bothering me for almost 4 years.
    Occasionly the applications terminated.
    Sometimes i got an error message.
    The problems were never reproducable.
    Last weekend the situation changed dramatically.
    Suddenly the problem occured on all available PCs and i could debug the crash.
    If i understand you correctly you tell me P/Invoke is not suitable for professional software development.
    I am a C++ programmer and i prefer mixed mode assemblies.
    Anyway there must be a serious bug in FolderBrowserDialog.
    FolderBrowserDialog is very often used so i would appreciate when it gets rid of the bug.
    Greetings Marcel
    Wednesday, February 2, 2011 8:16 PM