Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C#: How to find out *which* assembly or reference I am missing

I am using Visual Studio 2012. I understand that when I use new types, I need their using directive. I understand that different using directives require different assemblies or references.

I am fairly new to MS VS. Is there a simple way to find out which assembly or reference needs added for a particular using directive?

Example:

I just used the type FileContentResult. This is in System.Web.Mvc. Which assembly or reference do I add?

Again, I am asking for the general case, not just this case in particular. Ideally, I would like a trick I can use every time this happens, to quickly find the reference I need to add.

like image 509
trh178 Avatar asked Dec 20 '25 01:12

trh178


1 Answers

Not to sound to terribly old and crass, but the right way to figure out which assembly your types are in is to read the documentation.

From MSDN:

Namespace: System.Web.Mvc

Assembly: System.Web.Mvc (in System.Web.Mvc.dll)

If you're looking for something more immediate, the typical naming convention for .NET types is that they will be in an assembly that matches their namespace, or one of its parents, so start with the namespace you're trying to add and work backwards until you find a file with that name.

Unfortunately, there's no rule that things work this way, so you'll always have exceptions. One that drives me absolutely crazy is EntityFramework.dll does not contain the EntityFramework namespace, but rather System.Data.Entity, I assume because Microsoft was thinking -- I dunno what they were thinking, it's stupid. But at least MSDN helps you out there; for third party assemblies with bad names and no documentation, your best bet is to track down an assembly that looks like it might be related to what you're trying to use and ildasm and/or add it as a reference, and scan the metadata.

like image 131
Michael Edenfield Avatar answered Dec 22 '25 13:12

Michael Edenfield



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!