There is a corresponding VS dev ticket https://connect.microsoft.com/VisualStudio/feedback/details/817276/error-cs0012-the-type-is-defined-in-an-assembly-that-is-not-referenced-issued -for-an-extension-method-that-is-not-used
I have 2 extension methods:
public static class ExtensionMethods { public static string GetClientIpAddress(this HttpRequestBase request) {
The HttpRequestMessage is in the System.Net.Http assembly and the HttpRequestBase is in System.Web (that is, in different assemblies). The ExtensionMethods class is in the let ProjectA file.
This project compiles well and has no problems.
Then I use the first GetClientIpAddress(this HttpRequestBase request) method GetClientIpAddress(this HttpRequestBase request) from another project (e.g. ProjectB ), for example:
public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); var sessionContext = DependencyResolver.Current.GetService<ISessionContext>();
ProjectB already has a link to System.Web , but when I try to compile it, it causes a compiler error:
The type ' System.Net.Http.HttpRequestMessage ' is defined in an assembly that is not referenced. You must add a reference to the assembly ' System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a '.
What I do not understand, why should I add a link to System.Net.Http .
It seems that the compiler is trying to use the second method GetClientIpAddress(this HttpRequestMessage request) , and this leads to the absence of a reference to the assembly. This is mistake?
When I rename the first method (i.e. get rid of overloads), everything compiles well.