<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://interactiveasp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Tools' and 'Debugging'</title><link>http://interactiveasp.net/search/SearchResults.aspx?a=1&amp;o=DateDescending&amp;tag=Tools,Debugging&amp;orTags=0</link><description>Search results matching tags 'Tools' and 'Debugging'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008 (Build: 30417.1769)</generator><item><title>Avoiding Circular Dependencies</title><link>http://interactiveasp.net/blogs/natesstuff/archive/2008/06/09/avoiding-circular-dependencies.aspx</link><pubDate>Mon, 09 Jun 2008 21:45:06 GMT</pubDate><guid isPermaLink="false">b80005ef-4071-4968-b08e-765d7d71b33e:30</guid><dc:creator>NathanZaugg</dc:creator><description>&lt;p&gt;The term &amp;quot;circular dependency&amp;quot; may be foreign to some programmers (especially if you do Java as it is a pretty common practice).&amp;nbsp; However, anyone who has done some scripting for a referential database knows that you have to run scripts in a certain order.&amp;nbsp; Running scripts out of order causes errors when you run.&amp;nbsp; The interesting trick is that if you run that same incorrectly-ordered DDL script again and again you will eventually get it to run without errors.&amp;nbsp; If you were unaware of the order being incorrect and thought to yourself in that moment &amp;quot;Stupid database!&amp;quot; then this blog post is for you!&lt;/p&gt; &lt;h3&gt;What is a circular dependency? &lt;/h3&gt; &lt;p&gt;It is simply two libraries that use each other (either directly or indirectly) as shown below:&lt;/p&gt; &lt;p&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="107" alt="circular depencency" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/circular-depencency_5F00_3.jpg" width="240" border="0" /&gt;&amp;nbsp; &lt;/p&gt; &lt;h6&gt;Figure 1: Circular Dependency&lt;/h6&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image3.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="202" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image3_5F00_thumb.png" width="244" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt; &lt;h6&gt;Figure 2: Complex Circular Dependency&lt;/h6&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The complexity of a circular dependency may vary.&amp;nbsp; If you are using Visual Studio and have all of your projects loaded into a single solution AND you add Project References (Right click on project -&amp;gt; Add Reference -&amp;gt; Projects Tab -&amp;gt; {Project Name}) then the IDE will not allow you to create Circular Dependencies.&amp;nbsp; In fact, this is a good practice as Visual Studio will ensure the correct build order.&amp;nbsp; &lt;/p&gt; &lt;h3&gt;Why are circular dependencies bad?&lt;/h3&gt; &lt;p&gt;Just like our Database example above, a circular dependency makes it so you can not guarantee that your application has the latest code.&amp;nbsp; That is a big deal!&amp;nbsp; Here is why:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;I make changes to Application 1 (in Figure 2)  &lt;li&gt;I build my project, The changes I made in Application 1 may or may not have gotten into Application 2 (depending on build order).&amp;nbsp; It may have taken a copy of the compiled code that was left over from the last time I built.  &lt;li&gt;Application 2 depends on this new functionality to provide services to Application 3; This functionality will not work correctly with this build.  &lt;li&gt;Application 3 may or may not depend on these same services to provide &lt;strong&gt;back&lt;/strong&gt; to Application 1&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;As you can see in this scenario, there is no such thing as a &amp;quot;correct&amp;quot; build order when there are these circular dependencies.&amp;nbsp; The only way you can arrive at the correct version of the code is to build it as many times as there are nodes in our circle.&amp;nbsp; That would mean for Figure 1 that we would need to build twice and three times for Figure 3.&amp;nbsp; Some of these dependencies can get really ugly!&amp;nbsp; Here is some actual code running in an actual company that I did analysis on some time ago using a tool called &lt;a href="http://www.structure101.com/"&gt;Structure 101&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image9.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="150" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image9_5F00_thumb.png" width="143" border="0" /&gt;&lt;/a&gt; &lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image12.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="199" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image12_5F00_thumb.png" width="218" border="0" /&gt;&lt;/a&gt; &lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image15.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="196" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image15_5F00_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image18.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="244" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image18_5F00_thumb.png" width="202" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h3&gt;How do I fix circular dependencies?&lt;/h3&gt; &lt;p&gt;There are some steps to take to solve even the most complex tangles!&amp;nbsp; They all involve refactoring your code though.&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Refactor common code into a &amp;quot;base&amp;quot; dependency; I usually call this &amp;quot;&lt;em&gt;Common&lt;/em&gt;&amp;quot; (figure 3).&amp;nbsp; &lt;strong&gt;&lt;em&gt;BEST SOLUTION&lt;/em&gt;&lt;/strong&gt;  &lt;li&gt;Remove code that is unused.&amp;nbsp; In the tangles shown above many of them are using deprecated/unused code.  &lt;li&gt;Duplicate the sections of code used.&amp;nbsp; This should be seen as a &lt;strong&gt;&lt;em&gt;last resort&lt;/em&gt;&lt;/strong&gt; but given the choice between code duplication and circular dependencies, I take code duplication ever time!&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image21.png"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="173" alt="image" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image21_5F00_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;br /&gt;&lt;/p&gt; &lt;h6&gt;Figure 3: Refactor a Common&lt;/h6&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;h3&gt;Summary&lt;/h3&gt; &lt;p&gt;There are two kinds of design concepts for nTier (and other types of architectures as well) called &lt;em&gt;Logical Layout Design&lt;/em&gt; and &lt;em&gt;Physical Layout Design&lt;/em&gt;.&amp;nbsp; The Logical Layout is simply that your software occupies the same project/package but leverage different classes.&amp;nbsp; In contrast Physical Layout Design forces each tier to be separated into different Projects/Packages.&amp;nbsp; So long as we are careful to manage the dependencies between these packages from the start this is the preferable way to code.&amp;nbsp; While the logical layout does not suffer from the dependency problem eventually you may wish to break these classes apart and find that there are a lot of inner-dependency that should not exist simply because they occupied the same project.&amp;nbsp; &lt;strong&gt;Remember to keep it clean!&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>Debugging with Process Monitor</title><link>http://interactiveasp.net/blogs/natesstuff/archive/2007/12/05/debugging-with-process-monitor.aspx</link><pubDate>Wed, 05 Dec 2007 21:45:35 GMT</pubDate><guid isPermaLink="false">b80005ef-4071-4968-b08e-765d7d71b33e:13</guid><dc:creator>NathanZaugg</dc:creator><description>&lt;div&gt;Now I am not much of a low-level debugger type.&amp;nbsp; I&amp;#39;ve seen people use WinDbg like it was an extension of their hand!&amp;nbsp; I am not one of those people but I would sure like to be.&amp;nbsp; Lately I have been working on a project that does some pretty tricky code hooking of some User Mode API calls in Kernal32.dll.&amp;nbsp; Specifically I was hooking calls to CreateFileA, CreateFileW, DeleteFileA, and DeleteFileW in Kernel32.dll.&amp;nbsp; Everything was working as expected but when I drag a file in Windows Explorer I can see the CreateFile call being made in the Kernel, but I was not trapping those calls.&amp;nbsp; &lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;Of course, I looked in the call stack in Process Monitor, but without debug symbols, this information is pretty much useless.&amp;nbsp; All I could see is that Kernal32.dll called down to a lower kernel call and was eventually caught as CreateFile.&amp;nbsp; Well, I recently tried to get the symbols to work in Process Monitor and ran into some difficulty.&amp;nbsp; First, I needed the latest version of WinDbg installed as it uses the latest version of DbgHelp.dll.&amp;nbsp; Secondly the symbol path (as unusual as it is already in WinDbg) is slightly different.&amp;nbsp; For some reason Process Monitor needs to know not only where the symbols are but also the path to the executables that match those symbols.&amp;nbsp; I had to use the path: &lt;em&gt;&lt;u&gt;srv*E:\Symbols\*http://msdl.microsoft.com/download/symbols;E:\Windows\;E:\Windows\system32;E:\Windows\system32\Drivers&lt;/u&gt;&lt;/em&gt;&lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;My Symbol Settings&lt;/div&gt; &lt;div&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/PM1_5F00_2.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="184" alt="PM1" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/PM1_5F00_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;My Stack Trace now shows with symbols &lt;/div&gt; &lt;div&gt;&lt;a href="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/PM2_5F00_2.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="183" alt="PM2" src="http://interactiveasp.net/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/PM2_5F00_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;So my problem was that it is really making a call to CopyFileExW which uses the Kernel&amp;#39;s CreateFile function as part of the work it is doing.&amp;nbsp; Process Monitor doesn&amp;#39;t really know what the &amp;quot;parent&amp;quot; call for the stack is in the User Mode as it is a kernel level hook.&amp;nbsp; So while it looks like the call to CreateFileW in Kernel32.dll should have hooked this call, Kernal32.dll is actually a user mode dll and is just a shim to pass the call back to the Kernel to do the work.&amp;nbsp; &lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;Fun Stuff!&lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt; &lt;div&gt;&amp;nbsp;&lt;/div&gt;</description></item></channel></rss>