1

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.

Community
  • 1
  • 1
Daniel Arant
  • 483
  • 1
  • 4
  • 16
  • Yes, it's a microsoft bug. Go open a connect about it. Or, something is screwed up in the deployment environment. Why don't you switch on fusion logging and see where it's trying to find your reference? May enlighten you as to why the reference was located previously but not now. –  Apr 29 '16 at 20:02
  • If it's in the GAC, then it's got a strong name. You still referencing that exact version, or are you referencing a *different* version? Also, there might be binding redirects in web.config. Check out the runtime element under configuration. Look for the assembly you're having issues with. Is it redirecting your GAC version to a different one not in the GAC? –  Apr 29 '16 at 20:36
  • Good questions. I bumped up the version and file version of the assembly in question yesterday morning, whereupon I installed the new version in the GAC and incremented all of the references in the consuming application, as I've done scores of times before. After that, I went along my merry way coding, testing and debugging for the remainder of the day. The strong names would only have differed by the revision number. The Fusion Log Viewer sounds promising. However, it does not seem to be logging anything corresponding to the exception I'm seeing. – Daniel Arant Apr 29 '16 at 21:07
  • I don't ever recall having to do anything special to satisfy the compiler during dynamic compilation of ASP.Net resources. I've always just added a reference to the assembly in the web application and never hear a peep during dynamic compilation. That's what makes this so mystifying. If there was something wrong with the assembly name, then Visual Studio wouldn't be able to find the assembly either, and I would get build errors. – Daniel Arant Apr 29 '16 at 21:43
  • There's a tool for configuring fusion logging in the sdk. Find it, run the tool as admin, then reboot. If you don't do that, it will appear to work but not log anything :/ –  Apr 30 '16 at 16:40
  • It's logging a ton of other stuff. My concern is that, in this case, it isn't having a problem locating the assembly in question, so it won't necessarily show up in the Fusion log. It is not complaining that it cannot find the referenced assembly, it's complaining that the assembly is not referenced, even though there is clearly a reference in the project. It even knows where the type it is trying to compile against is defined. It is as if the dynamic compilation process is unaware of any project references. – Daniel Arant May 02 '16 at 13:00
  • @Will I added an update that sheds more light on the issue. The offending code seems to be a generic method I added to the page's base class that includes `MyClass` as a type constraint. Does that make any sense of what I'm encountering? – Daniel Arant May 02 '16 at 18:43
  • These dynamic compilation website errors can be weird. You've already taken this beyond where I've given up. I had this happen to me once, and I either fixed it by manually clearing out the asp.net temp files folder where compilation was taking place, or I just specified the assembly in the config. Dynamic compilation was never that popular, so it's pretty obscure and not well documented :/ –  May 03 '16 at 14:23
  • My understanding, though is that all .aspx files are compiled dynamically. Trying to dynamically compile .cs files is a completely different animal. Now that I know precisely which code is causing the issue, I re-framed re-posted the question, but for some reason people keep down voting it even though they can't answer it: http://stackoverflow.com/questions/36990411/why-is-my-use-of-a-generic-method-in-a-code-behind-class-resulting-in-a-dynamic – Daniel Arant May 03 '16 at 14:27

0 Answers0