1

Please see the code below (Image Hander):

<%@ WebHandler Language="VB" Class="com.Genie.PresentationLayer.Web.ImageHandler1" %>
Imports com.Genie.BusinessLogicLayer

Namespace com.Genie.PresentationLayer.Web
    Public Class ImageHandler1
        Inherits ImageHandler
        Private p1 as Person    
        Public Sub New()

        End Sub
end class
end namespace

com.Genie.BusinessLogicLayer was added to the GAC today. The application produces a runtime error when it gets to the Image Handler: 'Type Person is not defined'. Adding an assembly to the web.config as follows resolves the problem:

<assemblies>
        <add assembly="BusinessLogicLayer, Version=1.0.0.0, Culture=neutral, PublicKeyToken="669e0ddf0bb1aa2a"/>
</assemblies>

Why do I have to amend the web.config? I thought 'Add Assembly' was for website projects that do not use MSBuild (and therefore do not have 'References'). This is a web application project.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
w0051977
  • 15,099
  • 32
  • 152
  • 329
  • Are you sure that the Log4Net assembly reference in't in your `App.Config ` file in Winforms project? – VMAtm Jan 27 '15 at 10:33
  • 1
    ASP.NET uses the GAC just as a WinForms app. The actual assembly loading logs (see Fusion logging) or Process Monitor will tell you more about why it can't load the assembly. Perhaps a different version is in your bin directory. – CodeCaster Jan 27 '15 at 10:36
  • @VMAtm, yes I am. There is another assembly I have installed in the GAC (in house developed assembly) and this is not in the app.config either. Is 'Add Assembly' only necessary for web clients (ASP.NET)? – w0051977 Jan 27 '15 at 10:36
  • ASP.NET see the GAC contents as well as WinForms application, but it does a local copy in temporary folder for itself. May be there is a problem with permissions for your application pool identity for an ASP.NET site. – VMAtm Jan 27 '15 at 10:38
  • @CodeCaster, it is loading the assembly i.e. I can use the assembly from the app. There is just no reference to it (add assembly). – w0051977 Jan 27 '15 at 10:38
  • @CodeCaster, there are no runtime errors. The ASP.NET app is a web application and not a website. – w0051977 Jan 27 '15 at 10:42
  • @CodeCaster, sorry I thought I was clear. Please see the last paragraph of the question (I have justed added). – w0051977 Jan 27 '15 at 10:48
  • @CodeCaster, both applications work perfectly. There is no error. I have amended the last paragraph of the question again. Is that clearer? – w0051977 Jan 27 '15 at 10:56
  • @CodeCaster, I see runtime errors if I do not add the assemblies to 'add assembly' for assemblies that are in the GAC (for the web app only). For example, 'Type 'ILog' is not defined.' – w0051977 Jan 27 '15 at 11:00
  • @CodeCaster, I have added an update to my question. Hope it is clearer what I am asking. – w0051977 Jan 27 '15 at 11:13
  • See [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask). Include all relevant details. – CodeCaster Jan 27 '15 at 11:14
  • @CodeCaster, I have amended the question again after more debugging. I hope it is clearer now. – w0051977 Jan 27 '15 at 13:42

1 Answers1

0

The references you add to a project are used when the project is compiled, but an ASPX page or ASHX handler is compiled when it is first requested. At this time the references are lost, so you'll need to provide them yourself.

The alternative would be precompiling your ASPX pages, causing the error to be caught at compiletime as opposed to runtime, or moving the code to codebehind so your project's references will be used.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • That explains why I do not see the error when I 'publish' the web application to IIS Server. When I access the webpage on the IIS Server that accesses the Handler; the Handler is already compiled. Do you agree? – w0051977 Jan 27 '15 at 13:51