I have inherited an old asp.net webform WebSite Application, one of my recent projects I moved all the code from the app_code folder to a separate library. This has worked out great except for one page.
The page in question has no code behind and just uses embedded VB.NET code to do some work. The code needs to construct a type from the new library I created, Instead of looking for the type in the dll it looks in the App_Code dll and I get the following exception:
Could not load type 'CybersourceSecurity' from assembly 'App_Code, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
So I added the Import NameSpace and the Assembly reference:
<%@ Assembly Name="EA.Legacy" %>
<%@ Import Namespace="EA.Legacy" %>
Still I get the error. Code Below:
<%@ Page Language="VB" AutoEventWireup="false" EnableViewState="false" EnableViewStateMac="false" %>
<%@ Assembly Name="EA.Legacy" %>
<%@ Import Namespace="EA.Legacy" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head runat="server">
<title>Events and Adventures</title>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
</head>
<body>
<form id="form1" runat="server">
<div>
<%
Dim ky As String
Dim fm As Collections.Specialized.NameValueCollection
Dim sb As New StringBuilder
Dim cybsSecurity As New EA.Legacy.CybersourceSecurity
Dim ValidSignature As Boolean = False
Try
<Do a bunch of stuff that never happens because we blow up first.>
Catch ext As Threading.ThreadAbortException
'ignore
Catch ex As Exception
eventsvb.PageError(Me, ex, "CybersourceReceipt")
Finally
sb = Nothing
cybsSecurity = Nothing
End Try
%>
</div>
</form>
</body>
</html>
Full Stack Trace bellow:
[TypeLoadException: Could not load type 'CybersourceSecurity' from assembly 'App_Code, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.] ASP.accounting_cybs_receipt_form_aspx.__Renderform1(HtmlTextWriter __w, Control parameterContainer) in System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131 System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +315 System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +48 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +246 System.Web.UI.Page.Render(HtmlTextWriter writer) +40 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5290
[Edit] Note: This code works just fine in VS I can step through it with no exception, it only happens on the web server.
I figured it out,The key was it works in VS and not on the server, once upon a time the site was compiled down entirely into dlls including the aspx pages. I was able to repro the problem on the staging site then clean out the bin folder and the page started working. So I looked in the bin folder in production and found a dll with the same name as the aspx page,I deleted it, and all is well with the world. My take away: every time we push a new build to production we need to clear out anything that's no longer part of the project.