Click here to Skip to main content
Email Password   helpLost your password?

Sample Image - maximum width is 600 pixels

Introduction

This article will show you how Lutz Roeder's .NET Reflector can be made into an Add-In for Visual Studio.NET. It will be done using the ManagedAddIns framework.

Background

I started writing the ManagedAddIns framework when NUnitAddIn (a unit testing add-in project I have been working on) started becoming unmanagable. I have been developing it using VS.NET 2002 but it has worked on both 2002 and 2003 for a while.  I wanted to start developing it using VS.NET 2003 whilst maintaining compatability with 2002.

For the Impatient

If you're impatient and just want to see the Reflector add-in running - here's how you do it.  Install the latest version of ManagedAddIns.msi. That's all you will have to do! The new version includes the Reflector Add-In (make sure you uninstall any old versions first). Go to the 'Tools/Managed Add-Ins..' menu and select Reflector Add-In. The first time the Reflector Add-In loads it will prompt you to download Reflector. After the download Reflector should appear in a tool window.

Using the code

The add-in has been developed in 3 stages ranging in complexity from drag-and-drop to writing code that uses the Reflector SDK.  At each stage there was a fully functional add-in with differing levels in intergration.

At its most basic level ManagedAddIns allows you to run pretty much any Windows Forms application as a VS.NET add-in.  Simply select 'Managed Add-Ins...' from the VS.NET 'Tools' menu.  The add-ins toolbox should appear (dock it if it appears in the middle of the screen).  You can use this to add, connect and configure your add-in applications.  To run Reflector as an add-in simply drag Reflector.exe onto the toolbox (click save if you want to keep it).  To start the application double click or right click 'Connect' the Reflector entry.  At this point Reflector should appear inside VS.NET in a tool window.  You are ready to dock the tool window and start reflecting away.

There are a lot of applications where this is all you will ever need to do.  Just drag-and-drop and start running as an add-in.  On the other hand there are many applications that use tool windows in much the same way as Visual Studio.  Whereas these can work fine as Managed Add-Ins (particularly if you uncheck 'Dockable' on their tool window) they don't feel as integrated as they could be.  There is a tweak you can do in many cases to make tool windows appear as VS.NET tool windows.  This is done by declaring the tool window in the application's .config file.  Reflector is one of these applications and its tool window can be declared as follows.

<?xml version="1.0" ?>
<configuration>
    <configSections>
        <section name="managedAddIns"
                 type="MutantDesign.ManagedAddIns.ManagedAddInsConfiguration,
                       MutantDesign.ManagedAddIns" />
    </configSections>
    <managedAddIns>
        <managedAddIn name="Reflector">
            <toolWindows>
                <toolWindow type="Reflector.UserInterface.ToolWindow" />
            </toolWindows>
        </managedAddIn>
    </managedAddIns>
</configuration> 

As you can see a 'managedAddIns' config section is defined.  You will need to copy 'MutantDesign.ManagedAddIns.dll' from 'Program Files\ManagedAddIns\' to your application's directory.  In this case all controls of type 'Reflector.UserInterface.ToolWindow' will be created as Visual Studio tool windows.  The control's 'Text' property will be kept in sync with the tool window's caption and when the control is made visable the tool window will be activated.

This kind of tool window works well when the control is a container and you want the control's 'Text' property to be used as the tool window's caption.  In some cases you way want the control itself (rather than its contents) to be be parented by a tool window.  In this case you can declare the tool window as follows.  This would place the control called 'testSuiteTreeView' in a tool window with the caption 'Test Suite'.

<toolWindow name="testSuiteTreeView" child="true" caption="Test Suite" />    

At this point we have Reflector running inside VS.NET yet totaly oblivious to the fact.  Wouldn't it be nice if we could right click on a method and have the IL come up in Reflector?  Or even better right click on a VB method and have it decompiled as C#?  ;)  To do this we will need to hook into the guts of Reflector using the Reflector SDK.  We will be writing a Reflector add-in to connect to our VS.NET add-in!  To create a Reflector add-in you must implement the Reflector.ComponentModel.IPackage interface.

public interface IPackage
{
    void Load(IServiceProvider serviceProvider);
    void Unload();
}

The first minor issue was that Reflector is an EXE and it wasn't obvious how to compile against an EXE using VS.NET.  What you can do is rename Reflector.exe to Reflector.dll and add that to you project references.  Once you've done this exit Visual Studio and edit the .csproj file.  Rename the reference to Reflector.dll (and the file) back to Reflector.exe.  Once you've done this you're ready to start writing a Reflector add-in.

To use the Reflector .config and add-in source I wrote earlier, extract it into the same directory as Reflector.  The pre-compiled 'Reflector.VSAddIn.dll' will only work with version 3.2.5.0 or Reflector.  If you're using a different version you must recompile (it has been changing a lot recently so please check!).  Add Reflector to the Managed Add-Ins toolbox and double click/connect it.  Once Reflector has loaded inside VS.NET, select Reflector's 'Tools/Add-Ins...' menu item.  Select 'Add...' and add the 'Reflector.VSAddIn.dll' add-in.

At this point Reflector's context menu items should appear on the VS.NET code context menu.  You can now dissasembly, decompile and outline your code.  Best of all you can use this as a jumping off point to do the same to code you're calling!

Points of Interest

If you would like the Reflector add-in (or any other add-in) to always load you will need to edit the 'Program Files\ManagedAddIns.exe.config' file.  Change the 'startup' attribute to be true on the 'managedAddIn' element in question.  It should end up looking something like this.

<managedAddInRef assemblyFile = 
        "C:\Program Files\Reflector\.NET Framework 1.1\Reflector.exe" 
 startup="true" />

You can also add URL based applications to the Managed Add-Ins toolbox. For example you can run Chris Sells' Wahoo! game as an add-in by adding the following URL.

http://www.sellsbrothers.com/wahoo/wahoo.exe
You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
NewsReflector integration is now part of TestDriven.Net
Jamie Cansdale
8:35 3 Apr '09  
The Reflector integration detailed in this article is now maintained as part of TestDriven.Net.

You can find more information on my blog here:
Go To Reflector[^]
Debug With Reflector[^]

You can download TestDriven.Net from here:
TestDriven.Net[^]

Regards,
Jamie.

--
http://www.testdriven.net[^]
http://twitter.com/jcansdale[^]
http://weblogs.asp.net/nunitaddin[^]
GeneralDoesn't work, whidbey, orcas
Mickey Perlstein
8:19 27 Jun '07  
Hey,

I installed your addin from the source code here, but i couldn't get it to work.

I have Vs2005 and Orcas installed on my machine.
I can't seem to understand how to install it, or maybe it's different in vs2005?

I can't say anythnig about Orcas, as it's so brand new, you probably dont support it yet, but VS2005 is pretty damn old..



MickD'Oh!
Generalbad joke?!
bdaniel7
1:48 2 Mar '07  
Hello..

i was very excited about this Reflector add-in for VS .NET.

i downloaded TestDriven.NET 2.3 and started..
but surprise..when i rest the cursor within a member's name (be it method, field or whatever) that resides in an assembly and click "go to reflector", the reflector shows the code in my class Smile)

man..why would someone want to see his own source code in reflector?

i'm i dumb or what?..i tought i could use this reflector add-in to see the code for which i don't have the source..

Daniel
Generallatest version of reflector addin is not compliing on my box
shankalel
11:13 25 Sep '06  
I got latest reflector.exe from the site, renamed it to reflector.dll. I also got latest version of managedAddins and made it reference new version of reflector.dll. Whevever I try to compile project Reflector.VSAddIns, it gives me compliation
errors

e.g.

C:\Program Files\ManagedAddIns\AddIns\ReflectorAddIn\ReflectDebugCommand.cs(8): The type or namespace name 'Reflection' does not exist in the class or namespace 'Reflector' (are you missing an assembly reference?)

C:\Program Files\ManagedAddIns\AddIns\ReflectorAddIn\ReflectorAddInMain.cs(7): The type or namespace name 'ComponentModel' does not exist in the class or namespace 'Reflector' (are you missing an assembly reference?)


Generalnew version of Reflector.exe is not working on my box
shankalel
11:02 25 Sep '06  
I have .NET 1.1 on my box. I have one C# based tool which was using Reflector API in order to search for a mathod name in the entire source code to do impact analysis of how many times a method has been utilized and which are places where it is utilized

Following is the code -

IServiceProvider serviceProvider = new Reflector.Application(null);
IAssemblyManager assemblyManager = (IAssemblyManager)serviceProvider.GetService(typeof(IAssemblyManager));

IAssembly rAssembly = assemblyManager.LoadFile(DLLPath);


I got latest Reflector exe from the website, I renamed it to reflector.dll and I am getting compliation error that "Application class is not defined".

Could you please help on this?

What is the new way of loading any assembly as IAssembly object and iterating through it's classes, methods etc ?


Generalsite http://www.managedaddins.net down !?
dev tom
22:42 24 Feb '04  
your site seems to be constantly down Frown
do you still support it?
GeneralRe: site http://www.managedaddins.net down !?
Per Søderlind
10:29 11 May '04  
Seams like he has moved to http://weblogs.asp.net/nunitaddin

You'll find the ManagedAddIns at http://weblogs.asp.net/nunitaddin/category/1225.aspx


../Per
GeneralReflectorAddIn GDN Workspace
Jamie Cansdale
17:31 8 Oct '03  
I've created a Workspace for the ReflectorAddIn over at GotDotNet. You can find it here...
http://www.gotdotnet.com/Community/Workspaces/Workspace.aspx?id=df456a8a-d870-4792-8bb3-25a814091a8f

If you would like to hear about new versions, probably the most up to date place is my blog. You can subscribe to it here...
http://weblogs.asp.net/nunitaddin

Enjoy, Jamie.

GeneralPublicKeyToken has changed
AndyQua
9:47 7 Oct '03  
OK, just discovered this little gem and trying to get it to work with the current version 3.3.4.0 however when connecting to the Reflector.VSAddin addin I get the following error:

System.IO.FileLoadException: The located assembly's manifest definition with name 'Reflector' does not match the assembly reference.
File name: "Reflector"
at Reflector.VSAddIn.ReflectorAddInMain..ctor(Assembly reflectorAssembly)
at Reflector.VSAddIn.ReflectorAddInMain.Main() in D:\CVSHOME\ManagedAddIns\ReflectorAddIn\ReflectorAddInMain.cs:line 57

=== Pre-bind state information ===
LOG: DisplayName = Reflector, Version=3.2.5.0, Culture=neutral, PublicKeyToken=18ca6bb8dd6a03c3
(Fully-specified)
LOG: Appbase = D:\Program Files\ManagedAddIns\AddIns\ReflectorAddIn
LOG: Initial PrivatePath = bin\Debug;bin\Release
Calling assembly : Reflector.VSAddIn, Version=0.10.1294.6903, Culture=neutral, PublicKeyToken=null.
===

LOG: Redirect found in application configuration file: 3.2.5.0 redirected to 3.3.4.0.
LOG: Publisher policy file is not found.
LOG: Host configuration file not found.
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\config\machine.config.
LOG: Post-policy reference: Reflector, Version=3.3.4.0, Culture=neutral, PublicKeyToken=18ca6bb8dd6a03c3
LOG: Attempting download of new URL file:///D:/Program Files/ManagedAddIns/AddIns/ReflectorAddIn/Reflector.DLL.
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN

The public key token for the current Reflector is 4bc3d6f93ac9aace so I'm guess that the key has changed.

Any ideas?
GeneralRe: PublicKeyToken has changed
hughlynch
11:45 8 Oct '03  
Did you find a solution to this?

I would love to have Reflector integrated, but I haven't had any luck. Rebuilding the AddIn worked with the new Reflector version, but the AddIn still wont load. It keeps wanting to download, which doesn't work.

I've been searching the web for an old version of Reflector (3.2.5.0), but I've had no luck there either.
GeneralRe: PublicKeyToken has changed
Andy E
12:19 8 Oct '03  
Yes, I too gave up trying to get the download to work. First of all I tried at work but no dice - I put that down to firewall/proxy problems. Unfortunately, it didn't work at home either.

In the end, I manually downloaded the reflector assembly and unzipped it into the addin folder. I've also rebuilt the Add-in but it won't load because FileGenerator.dll has been built specifically with 3.2.5.0 so that needs to be rebuilt as well.

So I've given up.


GeneralRe: PublicKeyToken has changed
Jamie Cansdale
13:05 8 Oct '03  
I'll see if I can get something working tonight...
GeneralRe: PublicKeyToken has changed
Andy E
22:28 8 Oct '03  
That would be much appreciated.....

Wink
GeneralRe: PublicKeyToken has changed
Andy E
12:34 8 Oct '03  
Sorry - meant to a little clearer in my other post.

I'm having exactly the same problem as you. For you it's because the add-in needs rebuilding with the latest version of Reflector and for me it's because although I've rebuilt the add-in one of its dependencies (FileGenerator.dll) also needs rebuilding - you can verify this by opening either one up in Reflector - using the stand-alone rather than the add-in Smile since we're obviously sh*fted on that one at the mo.

GeneralVS.Net Freezes on Connecting to Reflector Problem
rs_tiin
17:11 4 Aug '03  
Hello

I used the "http://www.managedaddins.net/addins/reflector/" to install the addin. It downloaded the reflector. After that i opened ther ADDIN toolbox, selected Reflector AddIn and selected Connect. The first time it was ok(i guess).

After that i docked it in the Tool Window(where i have arranged the TaskList, Find windows etc). VS.Net just froze. I tried killing VS.Net, reinstalling the AddIn Manager. Nothing works. Can you pls tell m,e how to solve this prob

TIA

regards.

sr

GeneralVS.Net Freezes on Connecting to Reflector
rs_tiin
17:10 4 Aug '03  
Hi

I used the "http://www.managedaddins.net/addins/reflector/" to install the addin. It downloaded the reflector. After that i opened ther ADDIN toolbox, selected Reflector AddIn and selected Connect. The first time it was ok(i guess).

After that i docked it in the Tool Window(where i have arranged the TaskList, Find windows etc). VS.Net just froze. I tried killing VS.Net, reinstalling the AddIn Manager. Nothing works. Can you pls tell m,e how to solve this prob

TIA

regards.

sr

GeneralProblems using Reflector
TJachmann
22:49 29 Jul '03  
I've installed the latest version of ManagedAddIns and connected the reflector addin. It tries to get the latest version of Reflector from the web but never returns (i'm afraid our proxy is guilty. How can I reference a downloaded version. It doesn't seem to work with the newest 3.3.0.0 version (adding a reference to the reflector.exe to the toolbox works, but adding the addin to reflector produces a version mismatch?! If i try to open the csproj file of the addin and recompile, the reflector reference is broken (to what assembly should it point to?)

Best regards

Thomas
GeneralRe: Problems using Reflector
Jamie Cansdale
8:30 30 Jul '03  
Hi Thomas,

The install is supposed to download 'Reflector.zip', unzip 'Reflector.exe', rename it to 'Reflector.dll' and place it in the '\Program Files\ManagedAddIns\AddIns\ReflectorAddIn\' directory (I use the 1.1 version). If you do this by hand it should work. If you want 'Reflector Help' to work you should place 'Reflector.htm' in the same directory.

Someone has kindly submitted a patch to support proxy servers. I'm on holiday at the moment and haven't had a chance to include it. For the moment just the above by hand.

Please let me know if it works.

Thanks, Jamie.
GeneralRe: Problems using Reflector
rkiesler
7:20 20 Mar '04  
When I load the add-in from the managed AddIn Toolbox, it shows the status is Connecting... connected, then immediately disconnects. Reflector.dll (renamedfrom Reflector.exe) is in place (the download doialog does not show).

VS.NET 2003.
GeneralHow do you un-install
pleinair
18:36 22 Jul '03  
Do you have steps or script for un-installing?
GeneralRe: How do you un-install
Jamie Cansdale
1:45 23 Jul '03  
For the MSI installs you should be able to use Add/Remove Programs. If you want to remove something from the 'Add-In Toolbox', right click on the entry and 'Delete'. Let me know if you have any problems.

Thanks, Jamie.
GeneralNew Version for Updated Reflector
Jamie Cansdale
19:09 17 Jul '03  
Lutz has just upgraded Reflector and changed the version number. This will cause the above install to stop working. I've created a version that cators for changing versions numbers (not as simple as it sounds). You can find it on the Managed Add-Ins site...

http://www.managedaddins.net

Thanks, Jamie.

GeneralRe: New Version for Updated Reflector
p daddy
3:10 22 Jan '04  
Hi Jamie,

www.managedaddins.net has been down the past day or so - where else can I obtain the latest version?

Also, the zip file hosted on CP doesn't seem to be a valid archive...

Many thanks,

Paul Barrass

GeneralRe: New Version for Updated Reflector
Jamie Cansdale
8:01 22 Jan '04  
Hi Paul,

I'm planning to release some updated add-ins soon. If you subscribe to my feed over at http://weblogs.asp.net/nunitaddin you will be one of the first to know.

Thanks, Jamie.

Generalinstall
zhi
16:33 15 Jul '03  
I installed managedaddin 1.0.31 but in my tools menu of my Japanese version of VS.NET 2003 nothing appears. In "Addin Manager" menu I have checked "ManagedAddins" though.Confused


Last Updated 18 Jul 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010