There are several questions on Stack Overflow regarding the exception in question, but none of them seems to involve runtime compilation of an .aspx file, and none of the proposed solutions worked for me.
I have a web application that, as of yesterday afternoon, compiled and ran just fine. When I started working on it again this morning, I suddenly began receiving an exception at runtime, when IIS attempts to compile the .aspx page in question. (Type names have been changed to protect the innocent.)
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\MyWebApp\bdb24adf\eb592999\App_Web_MyPage.aspx.cdcab7d2.gibiyx2g.0.cs(148): error CS0012: The type 'MyType' is defined in an assembly that is not referenced. You must add a reference to assembly 'MyAssembly, Version=40.0.0.30, Culture=neutral, PublicKeyToken=7ca3fb5049101832
I can eliminate this exception by adding an assembly reference in the web.config, but I shouldn't have to do that. According to this stack overflow question, the only time that you need to add assembly references in a configuration file is when you are deploying uncompiled .cs code files in an ASP.Net application.
Neither the .aspx file nor the code behind file for this page has changed since everything was working yesterday. Nothing in the Web.config files has changed since yesterday afternoon either.
Short of changing the reference properties at design time or modifying the web.config, what can I do to get this bogus exception to go away?
Update:
The assembly that defines MyType
is installed in the GAC, which I have confirmed several times since I first started trying to figure out the problem.
Update:
I have finally honed in on the exact changes that are resulting in the exception. The .aspx page I am trying to view and which is throwing the exception has a code-behind class that inherits from a custom base page class.
public class MyPageClass : MyBasePageClass
I added the following method to MyBasePageClass
which, when commented out, makes the exception go away:
protected T CreatePartyPlaceholder<T>(T owner) where T : Party, new()
{
return new T { TemporaryId = owner.TemporaryId };
}
There are several other existing methods that refer to the Party
class, but this new method is the only one that uses the class as a generic type constraint.