go to definition in VS 2010 - c#

what do I have to do to jump to the right class not the metadata?
in visual studio 2010 while working on c# code I right click on some code to jump to "Go To Definition"
sometimes shows the right class where my object is define and sometimes show me the Metadata not the right class...
why is this ?
thanks for your help

It only shows you the source code of a class if that class is available in your solution. If you're referencing a project whose source you have, you can add it to the solution as a project reference, and "Go To Definition" should behave as you'd expect. If you're referencing a compiled DLL, "Go To Definition" will only display metadata.

if you added references to other project than F12 will go to the actual source code but for the DLL it will go to the meta data if defind

Visual Studio will go to the metadata when the reference is a DLL or an EXE - it doesn't "know" about the source code.
It will go to the source code when you have references a project.

As others have said, Visual Studio cannot show you the actual source code for an assembly that you only have in compiled form (i.e. .exe or .dll). If you really need to see how something was implemented, then you can use Reflector to decompile it for you, though the resulting code will probably be less intelligible than the original (no comments, variable names will be lost, etc.).

Related

"Peek/Go to definition" jumps to partial declaration in a tab named as "xxx[from metadata][Read only]" [duplicate]

I have a C# project which contains references to assemblies in DLL format. I have the PDB information for these DLL files, contained in the same folder. When I press F12 on a referenced member, I want to go to the definition of the member. Instead, it gives me the metadata, which of course I don't want.
When VS is debugging, it does go to the source code if I single step into that method. But if I press F12 on that method, it still brings me to the metadata.
There is a similar question here, but it only applies to project references, and the accepted solution has nothing to do with my issue.
"Go To Definition" in Visual Studio only brings up the Metadata
To summarize:
Referenced project is a DLL
I have the PDB information
Single-stepping in debug-mode brings me to the source code
F12 brings me to metadata
I want F12 to bring me to the source code as debug does.
EDIT: Adding as a "Project" is not an option as it creates additional complexity as our solution file references about five other projects which are all under separate source control repositories.
In Visual Studio expand the References section, select the reference to your related project (the one that contains the source code you want to F12 into) right click on it and select "Remove".
Then add the reference back to the project by right clicking on References and selecting Add Reference, under the Projects tab (if your using VS 2012) select (or browse for) the project you want to add a reference to and then click the OK button.
This will rebuild the reference and you will be able to F12 into the referenced projects source code. You will need to do this with all the projects in your solutions that are having this issue.
I don't know why this happens but at least the solution to the problem is rather simple
If you have ReSharper installed, you should bring up ReSharper options, and look for External Sources. There you can specify the relevant options:
It appears that this issue has been solved in Visual Studio 2013. Having the PDB information in the same folder as the DLL is showing me the source code when I use Go To Definition. I do not have the Reflector extension installed.
Is the referenced DLL a project in your solution? I find that when I have the source code for the project, and it's in my solution, Visual Studio is able to link to this code much more easily. (without showing me meta data).
Also, be sure to add the reference by "Project" in the References popup.
This is generally what I do anyways when I have this problem
Hope this helps!
PS. PDB files are usually just for debugging (both locally and remote) and are not used for source code reading in the way you are attempting to use it. ("Go To Definition")
One solution to this issue is to use .NET Reflector, VS or VSPro edition. This program will modify Visual Studio to provide the required functionality.
http://www.reflector.net/
Unfortunately, it costs $135 to $195, which isn't an option for everybody.
Add the reference as a project instead of ..\bin\Debug\referenceFile.dll
That solved my issue
I also used add reference as a project and my problem has been resolved and it's working great. Actually I was stuck at this point from very long time and finally i resolved this issue.
References -> Add References -> Solution -> Projects -> Select reference

Visual Studio or Resharper extension to decompile code

Does anyone know of a Visual Studio extension that will decompile assemblies and allows you to view code in Visual Studio for a given class instead of having to leave VS and use ILSpy or other "external" reflection tools? I Know Resharper also has a reflection tool but it would be nice if you could kick it off within VS.
Newer versions of Visual Studio 2017 now include an experimental feature called navigation to decompiled sources. It requires you to explicitly enable it (and restart Visual Studio), but once you do, you can see decompiled source code for assemblies your code references.
For instance, if you put your caret (text cursor) over the name of a method in a method call and press F12 (by default) it will open a new tab right in the IDE that shows the decompiled source code for that method. Microsoft says this uses ILSpy behind the scenes, but this is a lot more convenient and doesn't require you installing anything new.
I Know Resharper also has a reflection tool but it would be nice if you could kick it off within VS.
You can. With the cursor on an identifier, choose ReSharper | Navigate | Navigate To... (the keyboard shortcut in the VS scheme is Alt+`), and choose Decompiled Sources.
This uses the same decompilation engine as dotPeek, the standalone tool.
Note that within such a decompiled source, you must continue to use this same navigation method to follow definitions, as F12 or Ctrl+click will go back to the Object Browser.
Assuming the default short-cut keys where pressing F12 while a class/method is in-focus, you can set ReSharper to automatically decompile the reference. This ends up working great and it's as if the external assembly reference was like any other class in your source solution.
Example of source you are directed to when pressing F12 while focused on new HttpClient()
I suggest you to use .NET Reflector which has a built-in VS integration for assemblies decompilation and is far, far better than Resharper. Have a look at this page for further knowledge.
http://ilspy.net/ is free and Open Source. And has a plugin for Visual Studio.

Add DLL reference to visual studio macros

I need to create a lot of macros in visual studio the probelem is I do not know visual basic that good.
What I have been doing so far is:
Create the algorithm "Code" I plan to use on C# on a console
application. I complile it then decomplite it with reflector into
visual basic.
When I decompile the code I lose the comments plus sometimes I have to
refer back to the code and it becomes hard to manage.
I am tired of compiling and decompiling plus I have to make a few twick every now and then. I will like to create a service or library that I could reference somewhere through:
When I right click on reference and select add reference there is no way of selecting my own custom dll. Maybe there is a way of referencing the dll through code.
What I been trying to do is trying to register the dll so that my dll would appear in:
If I manage to register the dll it will be easier to supply my macros to other people...
Your answer might be here...
http://social.msdn.microsoft.com/Forums/is/vsx/thread/7b5d4c41-3a05-4a82-9a7d-aa6266fdbd25
....copy your assembly into
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies
(change the Visual Studio version number in the path as appropriate)
Related links:
C# for writing macros in Visual Studio?

Using Reflector To Create VisualStudio Project

I have a .exe app which I want to understand better - I can see it in reflector
Is there any way to get reflector to create a VS project with the code so I can view it properly in Visual Studio?
Nothing special is needed, it is built into Reflector, albeit not very discoverable. Right-click the assembly in the left pane and choose Export. You'll get a chance to change the output directory. Click OK and Reflector starts decompiling the code, creating a source file for each individual class. And creates a .csproj file which you can open in Visual Studio.
Check out Jason Bock's FileGenerator, it might be what you are looking for.
I've used Denis Bauer's Reflector.FileDisassembler http://www.denisbauer.com/NETTools/FileDisassembler.aspx. It works well enough to compile and step through the code.
Yea there is, but it doesn't come cheap
http://www.remotesoft.com/salamander/
I have used it to decompile assembly, but I've never used the feature to decompile it into a project so can't give you a review on that. The quality of the decompiler will match the one in reflector.
They also be some legal issues associated with decompiling exe into project - and source for recompilation, so use it with care.

Visual Studio debugging bug?

I am trying to debug a unit test. When I step into the code of the class I want to test VS2008 show the disassembly rather than the source. I have checked in the modules window and the status for the module in question reads "symbols loaded" so everything looks OK
The project is c#, I am using Visual Studio 2008 SP1, anyone got any ideas, it is driving me nuts!
Symbols and source code is not the same thing. You need either have the source code for your module in the same place on disk it was on the build machine, or set up the source server: http://msdn.microsoft.com/en-us/magazine/cc163563.aspx
If you right click in the source window, there will be a context menu option "Go To disassembly". That will show you what your looking for. Though, typically most people tend to ask how to get to source code from disassembly, not how to get to disassembly from source code! :)
#Grzenio is correct in that if you have the source and symbols and are still seeing dissassembly, something is out of whack.
Try checking for versions of the dll in the global assembly cache (GAC). You might also find other clues by checking the properties of any custom dlls that have been referenced. Specifically the properties "Specific Version" and "Copy Local". If either of these values are true, it could be a clue that the project references a GAC'd copy of a dependency dll.
Old post, but had this issue recently...
Delete the reference to the project for which you want to step through from the project calling the reference. Clean the solution, rebuild everything (which I like to do one project at a time when I have this issue). Add the reference again - ensuring you are adding the reference as a project reference and not directly referencing the .dll.
You can also try going to the debug settings and uncheck "Enable address-level debugging" under Debugging | General.

Categories