0
votes

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.

2
If you create a new page in the same folder, can you create a CybersourceSecurity instance from the codebehind of that new page?John Saunders
Yes we have a bunch of other pages that use the CyberSourceSecurity Class in the code behind. I forgot to add I don't get this error in Visual studio, I can step through the code and it works fine it only happens on the webserverAnthony
Is this part of a web site "project", or a web application project?John Saunders
Its a WebSite ProjectAnthony
It's important to say so - web site projects should be avoided, since they are different from any other kind of project in Visual Studio. One result of that is that those trying to help you will assume you are using a web application project and will give you bad answers.John Saunders

2 Answers

0
votes

alright it's working on your VS because it's using the reference locally, but on your server there is no such a reference, to fix the issue you just follow the instruction below:

Step 1 In Visual studio under your project solution click on References folder enter image description here

Step 2 Now right click on the a references that you want to embed them into your project and click on Properties , then you will see the Copy Local option is set to false, set it to true

enter image description here

Now save and rebuild your solution, then publish it on the server and that's it.

0
votes

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.