Results 1 to 11 of 11

Thread: [2.0] problems using DLL assembly.

  1. #1

    Thread Starter
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    [2.0] problems using DLL assembly.

    Hey everyone,

    I'm having a few issues using my DLL Assembly.

    When I run the following code in VS2005, it works without a drama

    Code:
    void SelectDefaultActivityCodes(string Search) {
    
            string _sql = @"SELECT DISTINCT ACC_COMP3, ACC_COMP3_DESCR1, ACC_COMP2, 
    	                    ACC_COMP2_DESCR1 FROM GLF_LDG_ACCT_DESC1 WHERE CHART_NAME = 'GLCHART' AND
                            ACC_COMP3 <> '' AND ACC_COMP3_DESCR1 <> '' AND 
                            GLF_LDG_ACCT_DESC1.ACC_COMP3 LIKE '" + Search + "%' ORDER BY ACC_COMP3 ASC";
    
            DataAccess _da = new DataAccess(_ciProdConnectionString);
            DataSet _ds = _da.ReturnDataSet(_sql);
            int _rows = _ds.Tables[0].Rows.Count;
            
            Response.Write("<table style=\"border:0px;\" cellpadding=\"0\" cellspacing=\"0\">");
            
            for (int i = 0; i < _rows; i++) {
    
                string _bgcolor = "#FAFAFA";
                int _rowColor = i % 2;
                if (_rowColor == 1) {
                    _bgcolor = "ECEEF1";
                }
                
                Response.Write("<tr class=\"SelectCodeItem\" style=\"background:" + _bgcolor + "\">" + Environment.NewLine);
                Response.Write("<td onclick=\"populateActivityCodeTextbox(this.innerText, 'txtActivityCode', 'ActCodeSuggest', '" + Server.HtmlEncode(_ds.Tables[0].Rows[i]["ACC_COMP3"].ToString()) + "', '" + Server.HtmlEncode(_ds.Tables[0].Rows[i]["ACC_COMP3_DESCR1"].ToString()) + "', '" + Server.HtmlEncode(_ds.Tables[0].Rows[i]["ACC_COMP2"].ToString()) + "', '" + Server.HtmlEncode(_ds.Tables[0].Rows[i]["ACC_COMP2_DESCR1"].ToString()) + "');\" style=\"padding-left:4px;text-decoration:underline;width:40px;cursor:pointer;border-bottom:1px solid #CED2D5;\">" + Server.HtmlEncode(_ds.Tables[0].Rows[i]["ACC_COMP3"].ToString()) + "</td>" + Environment.NewLine);
                Response.Write("<td style=\"width:280px;border-bottom:1px solid #CED2D5;\">" + Server.HtmlEncode(_ds.Tables[0].Rows[i]["ACC_COMP3_DESCR1"].ToString()) + "</td>" + Environment.NewLine);
                Response.Write("<td style=\"width:40px;border-bottom:1px solid #CED2D5;\">" + Server.HtmlEncode(_ds.Tables[0].Rows[i]["ACC_COMP2"].ToString()) + "</td>" + Environment.NewLine);
                Response.Write("<td style=\"width:160px;border-bottom:1px solid #CED2D5;\">" + Server.HtmlEncode(_ds.Tables[0].Rows[i]["ACC_COMP2_DESCR1"].ToString()) + "</td>" + Environment.NewLine);
                Response.Write("</tr>" + Environment.NewLine);
            }
    
            Response.Write("</table>");
            _ds.Dispose();
    
        }
    however, when i try to run it through iis, i get an NullReference error on the 'int _rows = _ds.Tables[0].Rows.Count;' line.

    Now, I am assuming this is because the ReturnDataSet function is not executing properly, due to problems referencing my InvoiceRequest.Core assembly... (using InvoiceRequest.Core is present)..

    It is a strong named assembly, and added to the GAC. the reference is added to my web.config file, and it makes no difference is the DLL file is in the Bin directory of my website or not.

    any help would be great.

    Cheers,
    Justin

  2. #2
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Re: [2.0] problems using DLL assembly.

    Is there any chance you can post the error message ?

    Parksie

  3. #3

    Thread Starter
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    Re: [2.0] problems using DLL assembly.

    ah yep.

    Below is the error message:

    Quote Originally Posted by Error Message
    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 69: DataAccess _da = new DataAccess(_ciProdConnectionString);
    Line 70: DataSet _ds = _da.ReturnDataSet(_sql);
    Line 71: int _rows = _ds.Tables[0].Rows.Count;
    Line 72:
    Line 73: Response.Write("<table style=\"border:0px;\" cellpadding=\"0\" cellspacing=\"0\">");

    Source File: e:\Development\Invoice Request\InvoiceRequest\getData.aspx.cs Line: 71

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
    getData.SelectDefaultActivityCodes(String Search) in e:\Development\Invoice Request\InvoiceRequest\getData.aspx.cs:71
    getData.Page_Load(Object sender, EventArgs e) in e:\Development\Invoice Request\InvoiceRequest\getData.aspx.cs:39
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +65
    System.Web.UI.Control.OnLoad(EventArgs e) +124
    System.Web.UI.Control.LoadRecursive() +97
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2491
    Thanks again

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: [2.0] problems using DLL assembly.

    Assuming you have exhausted any possible connection string and data query issues...

    I would suspect code access security, even as System.Data is marked as allowing partially trusted callers, most likely your InvoiceCore dll is not, and your web.config or your machine.config must be configured somewhere as running at less than FullTrust.

    The GAC assemblies are FullTrust by default, and when your application is run from the Intranet Zone, your InvoiceCore assembly is treating your web application as a partially trusted caller - thereby denying it access. The error is occuring in your InvoiceCore dll, so you most likely are NOT seeing it in your stack trace.

    You have three options:
    1) Remove the assembly from the GAC
    2) Apply the 'AllowPartiallyTrustedCallers' attribute to the Assembly. However, this leaves a gaping security hole, and requires utmost care in permissions - and is really a pain to deal with.
    3) Apply 'FullTrust' to your web applications - also a gaping security hole - depending on where the website will be deployed.
    Last edited by nemaroller; Oct 2nd, 2007 at 07:44 AM.

  5. #5

    Thread Starter
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    Re: [2.0] problems using DLL assembly.

    Ok, so i removed the assembly from the GAC, and had to comment out my assembly reference in my web.config file.

    The DLL file is still located in the Bin directory of mywebsite, except now I get this error.

    Quote Originally Posted by Error Message
    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0246: The type or namespace name 'InvoiceRequest' could not be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 11: using System.Web.UI.HtmlControls;
    Line 12:
    Line 13: using InvoiceRequest.Core;
    Line 14:
    Line 15: public partial class getData : System.Web.UI.Page {

    Source File: e:\Development\Invoice Request\InvoiceRequest\getData.aspx.cs Line: 13
    Line 13 is highlighted as the error line.

    I think I need to tell my site to look in the Bin directory, but I thought this was an Automatic Procedure

    The website will be running in an environment, where a user login (Windows Auth) is required to view this page. What sort of security hole would I be opening up using one of the other 2 options? Is it possible to do it without the bottom 2 options.

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: [2.0] problems using DLL assembly.

    Are you using the Web Application Project model (aka VS 2003) for your solution, or that atrocity introduced in VS 2005 (with App_Code and App_References folders)?

  7. #7

    Thread Starter
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    Re: [2.0] problems using DLL assembly.

    I have developed the assembly in visual studio, but am coding the pages in Notepad++, as visual studio is just way to bloated for my liking.

    I have not included an App_Code or App_References, as I thought the only folder required was Bin.

    I will do some research on the App_References folder. Both assembly and ASP.NET website are .NET 2.0.

    Thanks for your help, do you have any other suggestions?

  8. #8

    Thread Starter
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    Re: [2.0] problems using DLL assembly.

    I just found this in the msdn website, regarding the VS 2005 "Special Folders"

    Quote Originally Posted by MSDN Page
    Bin folder Contains compiled code, as in earlier versions of Visual Studio. Any classes represented by code in the Bin folder are automatically referenced in your Web site.
    how ever, it does not appear to be detecting this assembly. Could it possibly be IIS settings, as im only running it as a VirtualDirectory...does it need its own app pool or something?

    Cheers Again,

  9. #9
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: [2.0] problems using DLL assembly.

    Back in my day, we didn't have any fancy pancy 'special' folders that automatically made compiled assemblies available to a web project - we had to manually reference them.

    So, to your question, I don't have much experience with the new model since most enterprise shops have stuck with the old model for the straight forward manner in which it references other assemblies and compiles the web application into one main dll.

    All I can offer is something you probably already tried putting in your web.config.
    <add assembly="InvoiceCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=..."/>

  10. #10
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: [2.0] problems using DLL assembly.

    The problem is most likely not CAS; you would get security exceptions well before that method actually executed.

    I'd suggest taking a step back, and use Visual Studio to debug when your application is running through IIS. Ensure your assembly pdb is in the bin directory, alongside your .dll, then Debug > Attach to process; select aspnet_wp.exe (if on Windows 2000/XP) or w3wp.exe (Windows 2003).

    Once VS has loaded all the symbol files, drop a break point at the _da.ReturnDataSet(_sql) line, and start stepping through.

    I'm going to take a guess: I think there's an exception being raised in that method that is handled silently and defaults the return to null.

    Also, I can't be certain, but unless you're sanitizing the search query in the getData.aspx page, your code may be vulnerable to SQL injection.

  11. #11

    Thread Starter
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    Re: [2.0] problems using DLL assembly.

    hey everyone,

    It turns out that the problem was with the database. I used the .net TrustedConnection method.

    From this I conclude that when running the website from VS IDE, the ASP.NET process runs as your username, where as IIS runs it as a system account. I Did not know this, so the trusted connection wasnt actually working, as the system user wasnt a user of the db.

    I have since changed my connection string to include a username and password, and it runs fine.

    Thanks for all your replies,
    Cheers,
    Justin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width