Visual Studio 2010: How to understand your code using Dependency Graphs, Sequence Diagrams, and the Architecture Explorer

Have you ever had to work with a legacy codebase?  Designing new functionality on existing applications can be daunting.  There are always differences between the original design and the current implementation.  The new Architecture tools within Visual Studio 2010 help you to understand the application you have, design new functionality you need, and validate that your design and your implementation do not deviate.  In this post, we’ll look at how to understand the application that you have. 

Software can grow complex very quickly.  Whether you’re handed a legacy codebase that was created by someone else or you just want to get a better high-level view of the code that your team has produced, Visual Studio 2010 has some tools to help you better understand your code. 

Dependency Graphs

First of all, one of the biggest contributors to complexity is dependencies within your codebase.  To better manage your dependencies, you can create dependency graphs of your existing code.  Under the Architecture menu item, there is a option called “Generate Dependency Graph”. 


When generating dependency graphs, there are three options.  Collectively, these three options are called the “standard graphs”: 

  • By Assembly

  • By Namespace

  • By Class

Let’s walk through an example, using the .NET Pet Shop 4.0 codebase.  Under the Architecture menu item, I’m going to click on Generate Dependency Graph, By Assembly.  This will pop up a screen like this:


Under the covers, Visual Studio is making sure that everything builds, cracking open the assemblies, and building the graphs.  Once it’s complete, this will generate a DGML file.  DGML stands for “Directed Graph Markup Language”. 


This diagram shows the dependencies between your assemblies.  The thickness of the link line indicates the number of dependencies between the nodes; thicker lines indicate a stronger dependency. 

You can navigate through the diagram using Ctrl + mouse wheel to zoom in and out, or right-click and drag a boxed selection to zoom in on that.  When we drill in, it will show the namespaces that the assembly is dependent on (not all namespaces in the assembly), and we can drill down further to see the classes that your assembly is using too.  This is an easy way to visualize and explore your dependency impact. 

Notice the two pink-ish boxes near the bottom of the diagram.  The orange-pink box is labeled “Externals” and the purple-pink box is labeled “Generics”.  The Externals group contains all external dependencies that you have on code outside of your solution.  The Generics group contains all generics in your solution; the generics were grouped together to avoid cluttering the diagram. 

Let’s take a look at the PetShopWeb.dll node. 


The “2” in the upper left-hand corner indicates that there are 2 sub-items.  In the case of this diagram, it means that there are 2 namespaces within PetShopWeb.dll.  You can expand the node and see them by clicking the chevron icon in the upper right-hand corner of the node. 


Clicking on the PetShop.Web namespace to select it will also show you the dependency links (in purple) within that particular namespace. 


You can also expand the PetShop.Web namespace to view the classes used by your assembly.  Click the chevron icon in the upper right-hand corner of the PetShop.Web namespace node. 


Finally, let’s walk through the right-click menu…there is some cool functionality in there.  If you right-click on a node on the design surface, you will get this menu:


There are a couple of things in here worth calling out:

  • You have the ability to export/save your diagrams in other formats. 

    • “Save As XPS…” gives you the ability to export your diagram into XPS format. 

    • You can use “Copy Image” to copy and paste your diagram into Word.  (Note that just selecting the diagram and hitting Ctrl+C won’t copy the diagram into Word properly; you must use “Copy Image”.  Ctrl+C will copy just the DGML markup as XML.)  

  • “Categorize” – you can tag and annotate your nodes.  For example, if you find a node with a crazy number of dependencies, you could create a category called “Refactor” and then apply that category to various links or nodes.  It also color-codes based on categories. 

  • “Analyzers” – these tools allow you to find circular dependencies, hubs, and unreferenced nodes. 

Now, I’m going to clean up my diagram a little by deleting the “Externals” node.  This shows just the code in my system.  (Since I’ve expanded a bunch of nodes, I also right-clicked and selected “Group” then “Collapse All”.) 

Now I can click “Quick Clusters” to see the assemblies that are at the heart of my system.  The “Quick Clusters” icon looks like three little bubbles. 


Clicking on it produces a view like this:


Now, just from looking at this clustering, I can tell that PetShop.Model.dll has a lot of code depending on it, so I can make smarter decisions.  For example, if I’m triaging whether to make a change to that code and we’re fairly close to the ship date, I can make an informed decision that changing that code would be high risk to introduce bugs into the system, since there is so much other code depending on it. 

You can also drill all the way into code from these diagrams.  I’m going to expand the PetShop.BLL.dll, the PetShop.BLL namespace, and the Order class (using the chevron icons in the upper right-hand corner of each node).  Now I can see the individual methods within the class:


Now I can double-click on a method (for example, the Insert method), and it will take me directly to the corresponding code.  So you can navigate all the way to the code level. 

A few final fun facts on dependency graphs:

  • Out of the box, there is support for managed code only.  However, there is a feature pack coming with additional support for web (dependencies between pages) and native code. 

  • They can crack any .NET 1.1 assembly or up.  Yes, that is right.  This functionality is *not* limited to just your new .NET 4.0 code! 

  • These graphs can only be created in Visual Studio Ultimate edition, but they can be viewed and navigated with read-only access in Visual Studio Premium. 

  • You can create dependency graphs on obfuscated assemblies, but the names will be funny since it’s parsing the IL. 

  • You don’t need the source code; you can pull third-party assemblies into dependency graphs.  (Again, it’s using the IL to generate the graphs.) 

  • The DGML design surface is not available to rehost in your own applications.  However, you can utilize DGML if you write a Visual Studio plugin. 

  • The diagrams aren’t added to your solution by default.  One easy way to do this is to drag and drop the diagrams into the solution from the Miscellaneous Files in the Solution Explorer.  To check if Miscellaneous Files is enabled, go to the “Tools” menu item in Visual Studio and select “Options…”.  In the Options dialog on the left-hand side, expand “Environment” and select “Documents”.  Check the box for “Show Miscellaneous files in Solution Explorer” (see below).  Now the DGML file should be visible in the Solution Explorer, and you can add it to source control or whatever you like. 


Sequence Diagrams

I’ve navigated all the way down to the code level, and now I want to get a better understanding of what this code does.  One way that I can do that is to create a sequence diagram. 

Right-click in your code and select “Generate Sequence Diagram…”.  A dialog box will appear with some options, such as how many method calls deep to include in the diagram: 


This generates a UML 2.1 sequence diagram. 


It’s a visualization of your code flow.  You can also add proposed changes to your design.  For example, I might consider adding a method called ModifyPriceForRewardsCustomer.  I can do that by right-clicking on the box from which my new method would be called, and selecting “Add” then “Synchronous Message” (or “Asynchronous Message” if you prefer).  That will create a new message, which I can rename to reflect the method call.  This is a good way to brainstorm, visualize ideas, and share them with others.  Note also how when I add a new method, it appears in a different color (mustard yellow) to indicate that it is not implemented in the code (see below).  This clarifies what does exist in the codebase and what does not.  You can’t currently generate code from the sequence diagram. 


The if statements are represented as combined fragments (in the little boxes).  In UML terminology, a combined fragment specifies a group of lifelines/actors to show conditional flow in a sequence diagram. 

Finally, the analysis to determine dependencies and call information when generating the Sequence Diagram from code is all done statically. That means we are not going to pick up types that were loaded dynamically at runtime. 

There is full reference material on sequence diagrams at  Cameron also has done a few blog posts on sequence diagrams based on questions from the tour.  Check out:

Architecture Explorer

One last tool to help you understand your code is the Architecture Explorer.  The Architecture Explorer lets you go spelunking through your code, and when you find what you want, then you can visualize it using one of the diagrams. 

You can access the Architecture Explorer in Visual Studio by selecting the “View” menu item and then “Architecture Explorer”.  In the Architecture Explorer (see below), the first window on the left-hand side gives me different views to choose from.  I selected the Class View, which brought up the second window of namespaces.  I selected the PetShop.BLL namespace, which brought up the third window of types/classes.  I selected the Order class, which brought up the fourth window of members within the class.  I selected the Insert method, which brought up its calls to other methods.  In this manner, I can explore my code. 


You can select the items that you are interested in, and then use the icons on the far left-hand side to create graphs based on the selected nodes or add the selected nodes into existing graphs.  You can also build a query and save it into a DGQL (Directed Graph Query Language) file. 

In summary, there are some amazing features in Visual Studio 2010 to help you understand, explore, and visualize your code.  Stay tuned for tomorrow’s post where I will discuss how to maintain control of your software system

Comments (17)

  1. David Xu says:

    Nice post. I’m find the diagrams cool. But I’m also struggling to see how there useful.

    I found your 1 example to be very compelling: "For example, if I’m triaging whether to make a change to that code and we’re fairly close to the ship date, I can make an informed decision that changing that code would be high risk to introduce bugs into the system, since there is so much other code depending on it."

    If you could do a blog post on these types of examples…or examples only easy found using these new tools I’d be interested to read it.

    Nice step by step post…seemed like I could hear you talking me through each step.

  2. Dirk says:

    The Sequence Diagram stops just short of being really useful by not being able to go the other way and generate code from it. Any ideas when this will be added?

  3. Andy White says:

    I think the Dependency Graphs feature was released too early. The UI is very clunky and takes up CPU. Probably because it was written using WPF without perf improvements. I also think the information should be presented in a manner more easier to understand and navigate. Please try and make it like the Class diagram view.

    I like the sequence diagrams though.

  4. Gregor Suttie says:

    Arent these tools only available in the Ultimate edition of VS2010?

  5. Ian says:

    Nice, but on a large solution I get Out of memory errors for most attempts at visualization.

    What size solution can it handle reliably?

  6. jennmar says:

    @David Xu – thanks!  That’s great feedback on examples; I’ll try to do more of those.  

    @Dirk – There are some code generation capabilities coming in a feature pack that will be released in maybe a month and a half.  See Cameron Skinner’s “sneak peek” post on it at  Note that the code generation in the feature pack is from UML class diagrams, not from sequence diagrams, but more code generation is on the backlog.  🙂  

    @Andy White – thanks for the feedback.  What kind of CPU levels are you seeing?  

    @Gregor Suttie – yes, the ability to create these graphs is only available in Visual Studio Ultimate, but you can navigate and view them read-only in Visual Studio Premium.  

    @Ian – there is a great video on dealing with large solutions at  Chris Lovett has a bunch of videos related to the architectural functionality at  

  7. Nice Post.

    Thank you for your time

  8. Dan says:

    Thanks for an interesting article! How do I generate a Dependency Graph when I don’t have source code?  I’ve created a new Modelling project but I can’t see how to choose an .exe and/or a set of assemblies to be analysed.

  9. jennmar says:

    @Mehdi Mousavi – thanks!

    @Dan – Here’s the MSDN documentation on how to generate a dependency graph when you don’t have the source code:  Specifically, you would use one of these methods:



  10. Riccardo says:

    Hi Jennifer,

    thanks for the post. I'm trying to use the Dependency Graph – with no success – to detect the impact of source code change. This is the scenario: a developer changes the implementation of a method and he wants to know which are the top level calls/class (typically user interface / server calls) that are impacted so that he can know which functionality have to be tested again (this is useful when you have manual test). In this sense the exploration is not top-down (from assembly diagram, drilling to class / method) , but bottom (the method changed) up (all top references that use the changed method).

    In order to achieve that I generate the diagram of my solution. Unfortunately the solution is large and the number of asseblies generates a diagram that is too big to be usable seeing all the incoming nodes of the changed method. Moreover the visualization is not recursive.

    In other words, what I'd like love to have is a dependecy graph starting from a single node (this is feasible with Architecture Explorer)  and then having a "Include all incoming nodes (call to) recursive"

    In this way I will have a diagram consisting of the only nodes that will be impacted of my change.



  11. Farhana says:

    Hi Jennifer

    A very informative post!

    Given the vastness of the architecture topic,  I really liked the fact that you picked up the  basic tools and explained  how powerful they could be.


  12. Chris Lovett says:

    Responding to Ric, yes I agree the Dependency Graph feature has issues with this scenario on large solutions.  We are working on fixing that.  In the meantime, you might have more success if you use the Architecture Explorer to do a more targetted query by selecting the changed methods, then expanding next action column and selecting "Called by", and repeat this a few times, then graph the result.  Another thing you could try is generate the dependency graph then use "CTRL+F" to find the changed class/method and then click "Butterfly mode" on the toolbar.

  13. JimSz says:

    Great explanations Jennifer. I like the sequence diagrams but, the problem I am finding is that they are not refreshable once created. If I change the underlying code the diagram doesn't get updated and I have to recreate the sequence diagram. Does anyone know if there's a way to extend VS functionality to create an option to update the saved sequence diagram or if that functionality is in the pipe to be shipped later?



  14. very nice this is the beginning to see our app in a graph says:

    very nice this is the beginning to see our app in a graph

  15. jennyk says:

    This is great, I have VS2010 Ultimate and I can generate diagrams from existing dll and exe code. But what about ASP.NET web pages? When I click on "Generate Sequence Diagram…" on a method of an aspx page, I get the error:

    "VS1716: Cannot generate a sequence diagram due to the following possible reasons:

       A method is not selected. To generate from a property, select

       the get or set method inside the property.

       The solution or project is not open.

       The project type is not supported.

       The Visual Studio debugger is running".

    I am selecting my method, the solution & project are open, the debugger is not running. I have installed the "Microsoft Visual Studio 2010 Visualization and Modeling Feature Pack" and now I can automatically generate Dependeny Graphs for web code, but what about Sequence Diagrams? Most of our code is web code, the diagrams are not of much help if they don't apply to our web code.



  16. Binay says:

    Hi Jennifer,

    Thanks for the post, but in my Visual studio 2010 professional Architecture option is missing , what you suggest .


  17. Jyothsna Ch says:

    As far as I know, dependency graphs can be generated on assemblies. But I have requirement to generate dependency graph for functional testing. Is there any way for it to better utilize in functional testing. Provide any best alternative instead. Please give your suggestion asap.