7

Help!! I have a single .cs file under a (root level) App_Code directory for the purpose of retrieving the correct template for the requested URL (it is linked to our own Content Management database). Initially, it was working fine - I could make changes to it and they were picked up by the web application OK. Then something happened (no idea what) and now whatever changes I make, they are not recognised. Even if I delete the entire App_Code directory, it makes no difference - I still seem to be picking up an earlier (cached??) version of what was in the App_Code directory. Code in the .cs file is below:

using System;
using Custom.CMS.Facade;
using Custom.CMS.BO;
public class CMHttpModule : IHttpModule
{
    code here...
}

The same problem occurs even after I have copied the website to our live server.

What I don't understand is - if I introduce a deliberate error to the .cs code, I still get a compilation error, and on successful compilation an App_Code.xxxx.dll is created under C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

So what version of the App_Code is my web application actually picking up? How do I make it pick up the "correct" one?

FYI I am using C#, Visual Web Developer Express 2008 and IIS 6 web server

Any assistance would be gratefully appreciated.

Patrick
  • 71
  • 1
  • 1
  • 2
  • 1
    Did you try right-click solution -> clean solution. Rebuild? – Grant Thomas Jun 17 '11 at 12:10
  • Thanks mahesh. But Restarting IIS makes no difference. – Patrick Jun 17 '11 at 14:02
  • Mr. Disappointment - Visual Web Developer Express 2008 doesn't have a "Clean solution" option. Tried a rebuild but keep getting various errors which take me down more blind alleys. As I don't generally use the "build" option anyway on our sites, I'm sure the problem must lie elsewhere? – Patrick Jun 17 '11 at 14:08
  • did you manage to find a solution for this? I'm having the same problem! – David Aleu Sep 20 '11 at 16:14
  • @Patrick, I had an issue similar to this with silverlight applications I was creating. I found that incrementing the AssemblyFileVersion in the AssemblyInfo.cs file fixed my problem. Inititally this looked like a browser caching problem, and it was really confusing to get figured out. This may not tie into your problem since it doesn't sound like you're republishing your application, but I figured since you still don't have an answer I'd throw this out there as another dart at the dartboard. – Dan Jul 24 '12 at 18:18

6 Answers6

6

Reopening the solution also works.

Chris
  • 171
  • 2
  • 8
  • 1
    Thank you. Thank you. Thank you. Thank you. Thank you. 3 hours of my life gone trying to work out why I couldn't inherit a class from App_Code. I rebuilt the project. Checked for typos. Made sure I was inheriting and overriding correctly. Did the Google Dance. Screwed the project by moving a similar class out of App_Code. Spent time fixing the project. Yet, all I had to do was reload the project!! ARRHRHHGH!! Thank you, thank you for this suggestion!! – CResults Dec 18 '13 at 09:11
3

Can you right click the file, go to the properties and check the build action. It has to be set to 'Compile'.

Jeroen
  • 979
  • 1
  • 7
  • 16
  • i can't do that as it's only an issue on the hosted server where i don't have visual studio available – Sean Jul 26 '12 at 12:46
  • "I'm having this same problem. I uploaded a .cs file into the App_Code folder" - I don't think uploading a .cs file will do anything. IIS has a .net compiler, but it is only used for compiling asp.net webforms pages. Can you change your code locally, compile it on your machine and upload the resulting .dll and see what it does? – Jeroen Jul 30 '12 at 14:13
3

I'm not exactly sure how you're publishing your web application, but there are a few things you could try:

  • As mentioned previously, check that you are using project references instead of file references for the DLLs which are being built from your own C# projects. Also, check that your .cs file in the App_Code directory has its Build Action set to Compile
  • Check that all of the projects are targeting the same .NET framework: v2.0, v3.5, v4.0, or v4.5. You can check this in the Application tab of the Properties of each project. Do not use the Client Profile variation.
  • In your source code, delete your built DLLs (usually the ones in the bin and obj folders) and then use Visual Studio to perform a full build. This is the equivalent of a Rebuild (read: Clean then Build). Then, publish to your web server.
  • At the risk of stating the obvious, ensure that the web browser you are using to view your site has had its cache cleared before you hit the site.

Hope this helps.

EDIT: Just had a sudden thought: is this ASP.NET web application actually a web site? If so, then your code changes might not be recognized by the ASP.NET compiler because "if a code file is not referenced, it is not compiled."

The main difference between an ASP.NET web site vs an ASP.NET web application is that the former is typically compiled dynamically (automatically) by ASP.NET on the server the first time a request is received after the site has been installed or updated, while the latter is compiled fully into DLLs before even being published. You can read more about it in the links above.

Sameer Singh
  • 1,358
  • 1
  • 19
  • 47
  • "check that your .cs file in the App_Code directory has its Build Action set to Compile" - That was it. Mine was set to "Content" for some reason. Thanks. – billpg Mar 06 '13 at 12:06
1

@SeanW -

1) Did you try modifying your Web.Config instead of deleting it outright? The Web.Config is cached, but any revision to it should recycle your Application Cache.

2) Have you tried blowing away your whole site, and copying it out from scratch? (Especially be sure to delete and recopy any precompiled files in your bin directory.)

@Patrick -

1) Did you try deleting everything in your Temporary ASP.Net files directory?

2) If you had revisions to dependent projects in your solution (not your startup project), did you manually rebuild those dependent projects individually?

3) Do you have access to recycle the App Pool for your live web site in IIS?

4) Did you try recopying out your live web site from scratch or modifying the Web.Config in your live web site?

General App Cache Tips -

  • You can often refresh your Application Cache by making a trivial revision to your Web.Config file.

  • As discussed in this thread, Global.asax changes, bin directory changes, and App_Code changes may also trigger a refresh of the Application Pool.

  • As a long-term solution, you may wish to manage your Application Cache through a File Dependency or SQLCacheDependency Class. (Though that last suggestion may not work on shared hosting sites like GoDaddy.)

Community
  • 1
  • 1
Mac
  • 1,201
  • 2
  • 15
  • 28
1

I had the same issue yesterday and I fixed it making sure the class libraries references on the website project are pointing to your class libraries projects (not the dll's in the bin folder).

It looks because the website is targeting .net 2.0 and the class libraries are in .net 3.5 somehow the website project ignored the rebuilt dll's and used the ones in the website project bin folder.

David Aleu
  • 3,922
  • 3
  • 27
  • 48
0

ASP.NET Web Application has several traps. Reloading the project is one way to resolve several problems... Odd enough, indeed (call me bug)! Personally, I prefer ASP.Net Web Sites (instead of Applications) with JIT Compilation feature. FMO, it is quicker, easier and simpler way to maintain a prj.

Andreas Venieris
  • 452
  • 3
  • 15