ShaneKm ShaneKm - 11 months ago 114
ASP.NET (C#) Question

Get Location of Referenced local Assembly

I have ProjectA referenced by ProjectB in my solution. I'm trying to get a "path" of ProjectA, when running ProjectB.

I've tried this:

Running in ProjectB

// HomeController is in ProjectA
// This code is executed from ProjectB
var assembly = typeof(HomeController ).Assembly;
string filePath = new Uri(assembly.CodeBase).LocalPath;


Returns ProjectB path, instead of ProjectA path.

EDIT:
This shows UnitTestProject1 in the path. I want to get a path to WebApplication1.

enter image description here

Answer Source

To get location of referenced assembly use this

System.Reflection.Assembly.GetAssembly(typeof(SmsController)).Location;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download