<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Dat Bui's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/datbui/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/datbui/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:39:47 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>What to do when your application is behaving like a 5-year-old</title>
      <link>https://docs.microsoft.com/archive/blogs/datbui/what-to-do-when-your-application-is-behaving-like-a-5-year-old</link>
      <pubDate>Mon, 21 May 2007 16:18:00 GMT</pubDate>
      <dc:creator><![CDATA[datbui]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/datbui/2007/05/21/what-to-do-when-your-application-is-behaving-like-a-5-year-old/</guid>
      <description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; We get a lot of calls from customers about how to debug a misbehaving...]]></description>
      <content:encoded><![CDATA[<P>&nbsp;&nbsp;&nbsp;&nbsp; We get a lot of calls from customers about how to debug a misbehaving process and we end up asking for the same information most times.&nbsp; I hope this post will help a few out there maybe solve their problem, or cut the time it takes to resolve the issue by having the right information ready for MS Support to help.&nbsp; I am thinking of making this into a series, but lets see what I can cover.&nbsp; The information is scattered out there, but this is what we normally do.</P>
<P>Crashing Scenario</P>
<P>A crashing scenario is when the application terminates unexpectedly.&nbsp; This can happen a variety of ways, but usually a&nbsp; result of an unhandled exception.&nbsp; Most often if the <A class="" href="https://blogs.msdn.com/johnlawr/archive/2005/12/03/499821.aspx" mce_href="https://blogs.msdn.com/johnlawr/archive/2005/12/03/499821.aspx">error reporting system</A> of Windows has not been changed, an error dialog similar to "Send Error Report to Microsoft" will be displayed and there will be an application event log telling the module that failed, but actual cause of the crash is usually in a different module.&nbsp; I have seen a few times application just disappearing, no dialog, or anything mostly in managed code.&nbsp; This is usually a result of a manged heap corruption causing the crash.&nbsp; If the app is handling the exception and gracefully closing the application out or logging it, this is not a crash.&nbsp; The tools listed below will help in taking crash dumps for postmortem debugging.</P>
<P>Hanging Scenario</P>
<P>A hang is when the application is not responsive due to a dead hang, 0% CPU usage, or a busy hang, 100% CPU usage, where it needs to be killed.&nbsp; The dead hang can happen if the application is blocked from execution due resource contention, blocked or orphaned critical sections, or an indefinite wait for a resource or a piece of data to be processed.&nbsp; The busy hang mostly from unintended infinite loops/recursions.&nbsp; The question to ask here is how long the hang happens, if it's an indefinite hang there is an obvious problem, but usually the hang can happen for 30 seconds, 5 -10 minutes, or any random amount of time.&nbsp; With a hang scenario, a few hang dumps needs to be captured in succession to get a good picture of what's going on.&nbsp; Depending on how long the application hangs, divide that time up by 3,4,5 and at each interval of the process take a hang dump using adplus -hang or use debugdiag and it will give a good snapshot of the process over time.&nbsp; This can help determine which thread is hung when doing postmortem debugging.&nbsp;</P>
<P>Other special scenario, to be covered later.</P>
<P><STRONG>Tools to tackle the little bugger</STRONG></P>
<P>If the problem is happening during development then I am sure most will try and debug it as normal and resolve the problem.&nbsp; The following information might help those seeking help when stuck.&nbsp; Say the application is crashing on a production environment or on a customer's customer site and there is limited control/access to&nbsp;collect the right debug information to resolve the issue or the issue happens once in a blue moon.</P>
<P>The first thing that all developers need to be aware of when building their application is to always have symbol files, *.PDB,&nbsp;generated.&nbsp; These files should be saved for each build so that it can be used for debugging in the future if there are problems.&nbsp; A <A class="" title="Symbol Servers and Symbol Stores" href="https://blogs.msdn.com/controlpanel/blogs/mostly%20managed%20code%20where%20the" mce_href="https://blogs.msdn.com/controlpanel/blogs/mostly managed code where the ">symbol store</A> can be setup or it can be saved anywhere and pulled in later using a debugging tool like <A class="" title="Using a Symbol Server" href="https://msdn2.microsoft.com/en-us/library/b8ttk8zy(VS.71).aspx" mce_href="https://msdn2.microsoft.com/en-us/library/b8ttk8zy(VS.71).aspx">Visual Studio</A> or <A class="" title="Debugging Tools and Symbols: Getting Started" href="https://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx" mce_href="https://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx">windbg</A>.&nbsp; By default VS 2002 and later build symbols in release unlike VS6.0 which was not the default.&nbsp; Symbols for native/mix-mode modules are required and managed module is not really needed when debugging.&nbsp; It's always painful asking a customer to rebuild the application with symbols, re-deploy,&nbsp;and repro the&nbsp;issue again as not having symbols makes it very hard to debug the issue.&nbsp; Old symbols used for newer builds will not work.&nbsp; There's always the option to force load the symbol, but the call stack maybe incorrect and unreliable, so always make sure the symbols are from the same build as the application having the problem.</P>
<P>Once the symbol issue is resolved, now to start collecting the data to debug the problem with some tools used to live debug or collect <A class="" href="https://msdn2.microsoft.com/en-us/library/d5zhxt22(VS.71).aspx" mce_href="https://msdn2.microsoft.com/en-us/library/d5zhxt22(VS.71).aspx">memory dumps </A>for postmortem debugging.</P>
<P><A class="" title="IIS Diagnostics Toolkit (x86)" href="https://www.microsoft.com/downloads/details.aspx?familyid=9BFA49BC-376B-4A54-95AA-73C9156706E7&amp;displaylang=en" mce_href="https://www.microsoft.com/downloads/details.aspx?familyid=9BFA49BC-376B-4A54-95AA-73C9156706E7&amp;displaylang=en">DebugDiag.exe</A>:&nbsp; This tool is mainly targeting IIS process, but can be used for all processes.&nbsp; This tool is very user friendly and flexible.&nbsp; Rules can be setup to monitor a process and when it crashes a memory dump can be generated or manual dumps can be taken of the process while it's hung.&nbsp; It has added features to inject leaktracker.dll to monitor for memory leaks.&nbsp; The best feature is Advanced Analysis.&nbsp; This gives a pretty good overview of what is going on with the process or what is causing the problem, many times it will not point exactly to the cause of the problem.&nbsp; Can be used for both managed and unmanaged process, needs to be installed on the client machine.</P>
<P><A class="" title="Install Debugging Tools for Windows 32-bit Version" href="https://www.microsoft.com/whdc/devtools/debugging/installx86.mspx" mce_href="https://www.microsoft.com/whdc/devtools/debugging/installx86.mspx">adplus.vbs</A>:&nbsp; This is a script to attach the CDB debugger to the process to monitor it.&nbsp; This is a robust tool, but complex as config files need to be created to handle custom events.&nbsp; This tool comes with the installation Debugging Tools For Windows and can be used for simple crash scenarios to to take quick hang dumps.&nbsp; The documentation for the tool after install is very helpful, this works for both managed and unmanaged processes and does not need an install.&nbsp; Can&nbsp;xcopy the Debugging Tools for Windows&nbsp;directory to client, no install:&nbsp;&nbsp;&nbsp;&nbsp; adplus -crash -pn &lt;ProcessName.EXE&gt; -quiet&nbsp;or adplus -hang -pn &lt;ProcessName.EXE&gt;&nbsp; -quiet</P>
<P><A class="" title="Install Debugging Tools for Windows 32-bit Version" href="https://www.microsoft.com/whdc/devtools/debugging/installx86.mspx" mce_href="https://www.microsoft.com/whdc/devtools/debugging/installx86.mspx">windbg.exe</A>:&nbsp; Many articles on using this debugger.&nbsp; It's pretty powerful and can be used as a live debugger or a postmortem debugger.&nbsp; Works for both managed and native processes and can be xcopied over without having to install/register any components on client machine.</P>
<P><A class="" title="Description of the Dr. Watson for Windows (Drwtsn32.exe) Tool" href="https://support.microsoft.com/kb/308538" mce_href="https://support.microsoft.com/kb/308538">drwtsn32.exe</A>:&nbsp; Comes standard on all Windows OS, maybe embedded Windows is optional.&nbsp; So no install is needed.&nbsp; Only constraint is that it cannot collect dumps for managed processes.&nbsp; Use this tool in most restrictive environment, tool defaults to taking minidumps, need to configure it to take full dumps.</P>
<P><A class="" title="Debugging in Visual Studio" href="https://msdn2.microsoft.com/en-us/library/sc65sadd.aspx" mce_href="https://msdn2.microsoft.com/en-us/library/sc65sadd.aspx">Visual Studio</A>:&nbsp; Can be used to live debug and do postmortem debugging with some limitation on <A class="" href="https://blogs.msdn.com/scottno/archive/2004/07/26/197757.aspx" mce_href="https://blogs.msdn.com/scottno/archive/2004/07/26/197757.aspx">postmortem managed memory dumps</A>.&nbsp; Not the best tool to use in a limiting environment.</P>
<P mce_keep="true">If stuck, dumps and symbols are good data to have ready to pass onto support to get the help needed.&nbsp; I listed some links below those willing to read on.&nbsp; I'll continue this discussion on a later post talking more about debugdiag, adplus, windbg and how to use it to collect information to resolve the issue.&nbsp; There are lots of articles out there already on how to resolve, but collecting the correct information is the most important.</P>
<P mce_keep="true"><A class="" href="https://msdn.microsoft.com/msdnmag/issues/05/07/Debugging/#S2" mce_href="https://msdn.microsoft.com/msdnmag/issues/05/07/Debugging/#S2">Root Out Elusive Production Bugs with These Effective Techniques</A></P>
<P mce_keep="true"><A class="" title="SOS Debugging Extension (SOS.dll)  " href="https://msdn2.microsoft.com/en-us/library/bb190764(vs.80).aspx" mce_href="https://msdn2.microsoft.com/en-us/library/bb190764(vs.80).aspx">Managed debugging extensions</A></P>
<P mce_keep="true"><A class="" href="https://msdn2.microsoft.com/en-us/library/ms954594.aspx" mce_href="https://msdn2.microsoft.com/en-us/library/ms954594.aspx">Production Debugging for .NET Framework Applications</A></P>
<P mce_keep="true"><A class="" href="https://www.codeproject.com/debug/windbg_part1.asp" mce_href="https://www.codeproject.com/debug/windbg_part1.asp">Windows Debuggers: Part 1: A WinDbg Tutorial</A>&nbsp;(There are <A class="" title="Debug tips" href="https://www.codeproject.com/script/Articles/list_articles.asp?userid=961412" mce_href="https://www.codeproject.com/script/Articles/list_articles.asp?userid=961412">7 parts</A>)</P>
<P mce_keep="true">&nbsp;</P>]]></content:encoded>
    </item>
    <item>
      <title>Deploying .Net Assemblies with native dependencies</title>
      <link>https://docs.microsoft.com/archive/blogs/datbui/deploying-net-assemblies-with-native-dependencies</link>
      <pubDate>Wed, 09 May 2007 13:06:00 GMT</pubDate>
      <dc:creator><![CDATA[datbui]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/datbui/2007/05/09/deploying-net-assemblies-with-native-dependencies/</guid>
      <description><![CDATA[I know&nbsp;there are a few articles and posts out there concerning deploying .Net assemblies and...]]></description>
      <content:encoded><![CDATA[<P>I know&nbsp;there are a few articles and posts out there concerning deploying .Net assemblies and how to service them once they are out in the field, but I have not seen one that offers a method of deploying SDK type assemblies with native dependencies, meaning just DLL's with vendors developing against them.&nbsp; If you know of any send them my way.&nbsp; Some background:</P>
<P>1.&nbsp; Keep all assemblies in the local application directory, private assemblies</P>
<P>Basically the vendor would have to deploy 3rd party SDK DLL's with their app.&nbsp; This would make it very difficult to service the DLL's once it's in the field as there could be countless private assemblies sitting on the same machine in different folders, remind anyone of CRT redist issues?&nbsp; This would also put the burden on vendors to keep the private 3rd party DLL's up-to-date by continuously updating their application when the update needs to be done by the SDK vendor.</P>
<P>2.&nbsp; GAC all your DLL's</P>
<P>This is a good alternative.&nbsp; This is how the .Net framework works; each .Net assembly used in the CLR is GAC'ed so no one have to re-deploy the runtime DLL's once the client has the framework installed.&nbsp; Servicing is easy, they can have publisher policies to redirect binding to newer versions of the DLL's, this would be the ideal situation, or the app vendor can use app.config files to redirect binding to newer versions.&nbsp; But what about native dll dependencies?</P>
<P>GAC Phobia&nbsp; <FONT color=#0000ff><BR><A href="https://blogs.msdn.com/alanshi/archive/2004/03/28/100765.aspx" mce_href="https://blogs.msdn.com/alanshi/archive/2004/03/28/100765.aspx">https://blogs.msdn.com/alanshi/archive/2004/03/28/100765.aspx</A></FONT></P>
<P>3.&nbsp; What if you have native dependencies?</P>
<P mce_keep="true">In this scenario, you can create a multifile assembly, meaning .Net netmodules.&nbsp; This way your native assembly will be linked into the managed code so when you install the assembly into the GAC all the modules and the native DLL's will be copied into the GAC under it's own directory so minimizing probing issues.&nbsp; Servicing of native DLL's would be easy as you can rebuild and redeploy the new .Net assembly and redirect with publisher policy or app.config files.&nbsp; The other alternative is to wrap the native DLL's into it's own .Net assembly.&nbsp; This way you can keep the managed assembly separate from the native code and servicing can be more modular.</P>
<P mce_keep="true">There are a couple of issues with this, first the native DLL is platform specific.&nbsp; Meaning when you build a native DLL it's either x86 or x64 and .Net builds with "AnyCPU" configuration as default which is processor agnostic.&nbsp; So when you link in a native DLL, you will get this al.exe error AL1070, so building with /platform:x86 for all netmodules is required.&nbsp; The other problem is DLL bloat.&nbsp; This would load all the code modules into the process even if it's not being used.&nbsp; So some perf hit here if perf is relevant.&nbsp; Also when servicing this assembly a rebuild of the modules are required.&nbsp; This is different from GAC'ing all DLL's above is because the probing path for native dependency will be the standard probing path of the application so the native DLL would have to sit in the app's directory or maybe system32 which is not a good location.&nbsp; This method resolves the issue with servicing native DLL's that has .Net dependencies.&nbsp; </P>
<P mce_keep="true">csc.exe /target:module GACDLL.cs /addmodule:nongac.netmodule /platform:x86&nbsp;&nbsp;&nbsp;&nbsp; :building the netmodule with x86 as targeted platform</P>
<P mce_keep="true">al.exe /keyf:key.snk /link:nativedll.dll gacdll.netmodule /target:lib /out:test.dll /platform:x86&nbsp;&nbsp;&nbsp;&nbsp; :linking in native dll targeting the whole dll as x86</P>]]></content:encoded>
    </item>
    <item>
      <title>Powershell and .Net Loading</title>
      <link>https://docs.microsoft.com/archive/blogs/datbui/powershell-and-net-loading</link>
      <pubDate>Wed, 09 May 2007 11:10:00 GMT</pubDate>
      <dc:creator><![CDATA[datbui]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/datbui/2007/05/09/powershell-and-net-loading/</guid>
      <description><![CDATA[With the recent release of Powershell as a new command-line/scripting tool for system...]]></description>
      <content:encoded><![CDATA[<P>With the recent release of Powershell as a new command-line/scripting tool for system administrators, I see that .Net developers have been using the tool to automate their .Net applications.&nbsp; I noticed some issues arise when some customers try to load assemblies into Powershell.</P>
<P>When loading assemblies into Powershell, you should load the assemblies in the right binding context, use Load or LoadFrom and not LoadFile.&nbsp; The reason for this .Net is a strong typed framework, so loading assemblies with different load methods will treat the same types in each assembly&nbsp;as different types, type mismatch.&nbsp; Here's a good blog on this:</P>
<P mce_keep="true">Choosing a Binding Context<BR><A href="https://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx" mce_href="https://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx">https://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx</A></P>
<P>This is the error you would get if you were load using LoadFile and trying to instantiate the .Net object with dependencies using new-object, no TypeLoadException or any obvious exceptions.</P>
<P>New-Object : Exception calling ".ctor" with "0" argument(s): "Could not load file or assembly "..., Version=x.x.x.x, Culture=neutral, PublicKey<BR>Token=null' or one of its dependencies. The system cannot find the file specified."</P>
<P mce_keep="true">To resolve this you can use the following with some caveats:</P>
<P mce_keep="true">1.&nbsp; [Reflection.Assembly]::LoadFrom</P>
<P mce_keep="true">LoadFrom takes a path and will load assemblies in the same context as Load.&nbsp; The advantage is that the assemblies can be located anywhere.&nbsp; You just need to load the main assembly and it will&nbsp;load all dependent assemblies in that same path.&nbsp; This is the best, except when you do serialization you will get an error concerning type-mismatch because LoadFrom is not entirely the same as Load, explained below.&nbsp; So serialization assemblies show be GAC'ed or placed in local app's directory.</P>
<P mce_keep="true">Run-time Serialization&nbsp; <BR><A href="https://msdn.microsoft.com/msdnmag/issues/02/04/net/default.aspx">https://msdn.microsoft.com/msdnmag/issues/02/04/net/default.aspx</A></P>
<P mce_keep="true">2.&nbsp; [Reflection.Assembly]::Load</P>
<P mce_keep="true">You only have to load the main assembly and all dependent assemblies will be loaded when needed.&nbsp; The problem with this is that the DLL's needs to be in the application's local directory, in this case it's Powershell's:&nbsp; C:\WINDOWS\system32\windowspowershell\v1.0.&nbsp; This is actually messy, might use it temporarily since you will need to dump all dependent assemblies into the directory.</P>
<P mce_keep="true">3.&nbsp; GAC everything which is not the best thing or use a script to create a new AppDomain and load everything into it and you can also have a config file to set assemblies private path, I have not tried yet but seems possible with Powershell :)</P>
<P mce_keep="true">Use fuslogvw.exe tool part of the SDK to troubleshoot binding and probing issues and this article is a good read as well.</P>
<P mce_keep="true">How the Runtime Locates Assemblies<BR><A href="https://msdn2.microsoft.com/en-us/library/yx7xezcf(vs.71).aspx">https://msdn2.microsoft.com/en-us/library/yx7xezcf(vs.71).aspx</A><BR></P>]]></content:encoded>
    </item>
  </channel>
</rss>