In NetBeans using Java I can open java.lang.String class and I see that class source code. If I try to open System.String class in VisualStudio I see methods signatures only.
Is it possible to install VisualStudio plug-in or something like that to open mscorlib classes source code pressing F12?
Thanks for your answers.
I've found the best solution for me: http://visualstudiogallery.msdn.microsoft.com/95789cdb-08f9-4dae-9b2f-fc45a452ad77
What you want is at "Microsoft Reference Source Code Center", with the .NET Library sources at http://referencesource.microsoft.com/.
What you are asking for can be achieved by using dot peek from Jetbrains.
Jetbrains offer some other cool software too, like Resharper which can have dot peek included and you can navigate to the decompiled sources.
You can get the actual source code, not decompiled, from the symbol files which is the option beneath the one I have highlighted, you would need to do what the other answer says by setting up your symbol server.
UPDATE: See Bruno Brants answer.
While the previous answers are good, you have a better option now: Microsoft has open-sourced .NET, and not only that, all of it is available at GitHub.
Also, it's now possible to configure Visual Studio to check referencesource.microsoft.com while debugging.
Related
Coming from Java world and now learning .NET 7 development in addition, I'm embarrassed to say, I cannot figure out how to open/view relevant API Reference documentation from within the IDE.
When I right-click a Dependency (Package) in Solution Explorer, I would expect an option to open the documentation which accompanies the given NuGet package. In short: How to open this documentation? (i.e. not for a specific class, but for a package as a whole)
When I right-click a namespace in say a using Foo.Bar directive in the code editor, I would expect an option to open the documentation for Foo.Bar (show of classes, etc). I cannot find such an option.
If I hover over a class name or right-click a class I would expect an option to display documentation for that class (its description, which methods does it have?, which properties? .. and so on).
I understand as much as that the equivalent of JavaDoc is some XML stuff which is typically bundled with each NuGet package. It is basically this that I would like to browse in HTML form. Or some other form which provides me an overview of which classes and interfaces exists, their methods, cross refs, and so on.
I'm aware of the F1 option in the code editor. However, it only works for stuff which is from Microsoft (it does an MSDN search).
For all the packages I use, I can see the XML file exist on disk, so for sure it is there.
I use various third-party libraries and some of them are kind enough to publish API Reference documentation on their website .. if you can find it. It all looks slightly different in terms of skin (I can live with that), but there doesn't seem to be a convention for how this documentation is made available to the library user as I'm used to in Java world. So I need to hunt for it?
Please help a newbie.
IDE: Visual Studio CE
Language: .NET 7
I can see that this would be helpful, but what you are looking for doesn't exist. There's no centralized location for the documentation of non-microsoft packages. So if you want an overview over the classes of such a package, it's best to google for it (or visit the project's github page).
There are several ways to get to the information you want/need:
If you want to know the methods/properties of a class, just type a dot after an instance of the class to see the possible elements in a menu. If documentation exists, the description of the different methods will also be shown, together with the required parameters.
If you want to know about all the classes in a namespace, you can do the same, just explicitly type the namespace to get the list of classes.
Of course, you can also use a tool such as Ildasm or jetbrains dotPeek to get the class structure of an assembly/nuget package.
None of this is really a HTML documentation, but as said, that only exists if the package providers generate and provide it.
When I'm using aspnet_compiler.exe to pre-compile my website, I see a cvtres.exe process along with csc.exe. I'm assuming this is part of the .NET compilation process, and would also show when compiling my .NET assemblies. What is cvtres.exe and what does it do?
Windows Resource to Object Converter (CvtRes.exe) (from here)
As to what it does, well... I guess that it converts Resources to Objects.
Edit: As Scott says,
to be more specific, it is part of the C++ toolchain to turn resource
files (.res) in to compiled objects that can be linked using the
linker.
I was looking for something official that explains it, but the best I could find is an old support article that mentions it. Hope it helps!
I've referred the file System.Security.dll as described in this article but according to my IDE, the line using System.Security.Cryptography; can be safely removed as it's not being used.
The same IDE tells me that I've got an error with DataProtectionScope and ProtectedData. Those are supposed to be in that namespace. However, when I dot my way through the packages, I can't see them in there.
Is the article wrong? How can I access the two classes?
As #Coral Doe mentioned in a comment under #Dave Lucre:
"Had a similar problem and this worked. using System.Security.Cryptography; didn't [show] me [ProtectedData] and ProtectedMemory until I had referenced the System.Security.dll for the specific framework."
This fixed the issue for me. Specifically, I performed these steps:
Open the project in Visual Studio.
Right-click the project's name in Solution Explorer then choose Properties.
Click the References tab on the left.
Click the Add button.
Click the .NET tab.
Select System.Security and click OK to add the reference.
Hope this helps.
I have referenced the System.Security.dll here: C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Security.dll
Added using System.Security.Cryptography; and I can see both DataProtectionScope and ProtectedData.
I'm targeting the .net 4.0 full framework (not client profile).
What framework are you targeting?
I had to add this NuGet package in addition to System.Security.Cryptography.
It is https://www.nuget.org/packages/System.Security.Cryptography.ProtectedData/.
After that, System.Security.Cryptography became "used".
As #Dave Lucre asked, what framework is your application targeting? Visual Studio creates all new applications to use the Client Profile by default (which is asinine in my opinion), and it causes all sorts of trouble if you don't specifically change it back. Give that a look, then see where we go from there.
Remove references System.Security.Cryptography and add it again.
It works in my case.
I'm sorry, I know that this is a quite old post, but I'm having this issue now and the only workaround that I've found is:
Follow the steps mentioned in George Brian's answer
Use System.Security.Cryptography.DataProtectionScope scope = System.Security.Cryptography.DataProtectionScope.LocalMachine; instead of DataProtectionScope scope = DataProtectionScope.LocalMachine;
This might be a slap in your face because you've probably tried that (and you haven't, you might deserve one). What happens if you reinstall the whole IDE? And I meant really the whole thing. Remove the framwork, the VS, remove the files, go paranoid and clean up the trash can, switch to a different installation directory etc. Does the problem still remains?
I know it doesn't explain why it happened but at this stage I'm guessing you're mostly interested in how to kill the problem.
If you have access to a spare computer - why don't you install VS on that machine and see if you can reproduce the error. If not, then there's something fishy with your primary machine and you'll probably never know what happened.
I'm stressing here that it's only a list of general suggestions that every programmer should rely on when nothing sane nor logical seems to work. And yes, I do hate computers. I love programming but I hate computers. They are like small, evil people with keyboards...
I'm new to .NET C# programming. I'm following few books. It is said that instead of compiling C# code directly to machine code, it is converted into an intermediate language (called MSIL aka CIL). But when I compile, I get an exe/dll file.
Is this MSIL/CIL contained in these exe/dll files?
I want to see that intermediate language code, just to get feel for its existence. How do I view it?
They are calling this exe/dll file an assembly. Are they using this "fancy word" just to differentiate these from the exe/dll files that contain native/machine code?
Yes it is, more exactly in the .text section of the PE file (portable executable = *.exe or *.dll). More information can be found here.
The best choice is to use ILSpy (Reflector is no longer free). It's a free disassembler that can dissassemble your assembly into MSIL but also C#, VB (to some extent). The .NET Framework SDK contains ILDasm, which is the official MSIL dissasembler.
Basically yes. An assembly is a file that contains MSIL code and corresponding metadata. This is not restricted to PE files per se, but all current CLR implementations use them.
If I may recommend a good book on that matter too, it's Expert .NET 2.0 IL Assembler by Serge Lidin. He's the guy who designed MSIL.
One of my favorite ways to see IL for a snippet of C# is to use the free LINQPad tool. After entering some code and choosing "C# statements" at the top (or "C# Program", whichever suits), click the "IL" button under the code entry area, and you will see the generated IL.
Using LINQPad for this is much more convenient than loading up Visual Studio or running the compiler from the command line, then loading up ILDASM and opening the .il file with a text editor.
If you want it online, .NET Fiddle is excellent. Just paste your code and click View IL option at the top right.
Another option: Use ReSharper
Source / IL synced view: left blue background line corresponds with right IL Block
In Visual Studio:
Choose ReSharper | Windows | IL Viewer
or Context Menu: Navigate | IL Code
Supports synced view of Source Code and IL - when you click on a statement in source, the corresponding block in IL is highlighted (and vice versa). Displays descriptions for IL from Microsoft Developer Network and "Common Intermediate Language (CIL) instruction set" from ECMA standard specification.
see Viewing Intermediate Language (IL) in Resharper Help. Picture above is from Resharper Help.
Free option is to use Jetbrains dotPeek
see also: "Exploring Intermediate Language (IL) with ReSharper and dotPeek", by Maarten Balliauw, January 19, 2017 - Jetbrains Blog
sharplab is an online tool, great for simple use cases. Type your code on the left, IL shows up on the right.
I believe that they are called "assemblies" because an assembly is a set of modules, assembled together by a manifest.
(source: microsoft.com)
See Assembly Contents for details.
Yes it is in assembly.
You need .NET Reflector or ILDasm.
More details on assembly check HERE.
P.S As you are following some books I will highly recommend you CLR via C#.
In many respects, .NET assemblies are similar to Java bytecode packages.
Yes. They also contain manifests and other data, but the CIL is part of the exe/dll.
Use ILDasm or Reflector - most people would say Reflector, as it is much more powerful. Both will show you what CIL was produced. Wikipedia has a list of all CIL instructions, for a better feel (it is assembly like).
I guess it is meant as an assembly of code. A good way to differentiate it from native.
I know this is an old question, and I'd prefer any of the tools above. However, in a pinch, there has been an MSIL viewer in the box with Visual Studio since at least Version 2005.
The tool is named ildasm.exe, and is located in the following folders after default Visual Studio installations:
Visual Studio 2005
"C:\Program Files (x86)\Microsoft Visual Studio 8\SDK\v2.0\Bin\ildasm.exe"
Visual Studio 2008
"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\ildasm.exe"
Visual Studio 2010
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\ildasm.exe"
For more information, see: "How to: View Assembly Contents" in the MSDN Library.
I have just spent a couple of hours searching for the best tool that could let me view the IL code directly inside Visual Studio.
The only solution I found so far is Msiler https://visualstudiogallery.msdn.microsoft.com/60fc53d4-e414-461b-a27c-3d5d2a53f637
it works quite well!
Otherwise the second best solution, but without visual studio integration, is JetBrains dotPeek, which is quite awesome to be honest.
From my experience the best source of IL-related knowledge is Andrew Troelsen “Pro C# and .NET Platform”. Starting from 3rd edition he has really, really outstanding chapter (approx 50 pages) on how to understand IL and even write your own code and use ILAsm. I’ve employed that information to investigate whether multiple inheritance exists in .NET world. Also you could try to employ some very interesting features in IL (e.g. filtering of exceptions which only exists in VB but not in C#).
I highly recommend to read that chapter.
Eventually, .NET Reflector is an enterprise standard for investigating IL code of assemblies and Richter's book is definitely "must read" stuff. But from other books like mentioned above you could reveal really useful things :)
Yes, each assembly in .NET world holds some IL code (alongsite with manifest) which could be viewed thru Reflector or ILDasm. Even more, Reflector could show you C# and VB optimized code. This means that any person could view the source code of an assembly and that's why in commercial products obfuscators are used.
I you want to view the intermediate language, Try downloading JustDecompile from Telerik (Which is currently free, requires a sign up though).
Drag in your DLL and choose IL from the drop down box at the top!
There is now another option. You can do this in VS Code with this extension built with Roslyn. This is currently limited to .NET Core.
Hi kind of a newbie question.
So apparently this library is popular for this sort of thing:
http://extracting.codeplex.com/
When I download that all I get is a .dll
I can't find documentation on their api, I don't know what I'm supposed to do with this .dll (I know how to load in functions from DLLs and such, but how when I don't even know whats in it?), can someone help me out.
start a new c# project. Open the add reference dialog and use the broswe tab, select the dll.
now open the object browser - you will see all the functions etc
edit: of course you can also download the source code from codeplex; always the ultimate form of documentation
There's a link on the same page pointing to the API documentation containing sample usage.
There is a link to an example on the codeplex site
http://extracting.codeplex.com/wikipage?title=Web%20Data%20Extracting%20and%20Analyzing%20Framework%20API&referringTitle=Home
They have limited documentation on the codeplex site, available here.
I would recommend checking that documentation to see if it meets your needs, and asking any addition questions in their Discussions Page.
To use the functionality of the DLL from your project, right click on your project file in the Solution Explorer and choose "Add Reference..". You will be presented with a dialog to choose the reference you want to add. To choose the DLL from this library, browse to it from the Browse tab.
Once you've added the reference, you won't notice a whole lot of difference - all adding a reference does is give you access to the classes that are defined withing that DLL (called an "Assembly" in .NET terms). Think of it like getting a new set of "built-in" classes in your project that you can now use. You'll want to find some documentation or ask for help on the site to learn how to use these classes.
if you are using visual studio, you can just include the dll into the reference folder of your project and then use the "using" keyword to include the library into your namespace ...
If this is a .NET assembly, then reflector will tell you what classes and methods are available. You can also reference the DLL from a C# project and then press "ctrl-alt-j" to bring up the object browser to see that data inside of Visual Studio.
You can download the source code from that page.
Look at the classes and namespaces. You can add a reference to the DLL to your project and add "using" with the namespace of the DLL to the top of any code files you need to use it in in order to have access to the classes.
Additionally you can look at some of the examples posted.
Load the dll into .net Reflector. This will list the contents of the dll and any code comments associated with the API.