Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default DllImport Error

    Hello friends,
    I need to load an unmanaged dll(which i wrote for license control)
    from system32 folder and then my asp. net project will read the values
    from there.(I'll write the full code to the bottom)

    I get an "Object reference is not set an instance of an object
    error"...This code works in my local machine , but in our remote
    machine there was a problem that i told above. I can only fix the
    problem by iisreset , but problem repeats again and again for a while
    later... The problem is in DLL Import section... full code is here
    where it broke...
    i am sure u can help me to solve this problem thanx everybody...

    private int CheckLicenceApply()
    {
    PortalSettings portalSettings =
    (PortalSettings) HttpContext.Current.Items
    ["PortalSettings"];

    int i= 0;
    // error is in here when trying to load dll
    i = Mydll.LicenceApply
    (portalSettings.PortalTitle,GetLicense().ToString( ) ,
    ProductGroupKey, ProductMagic,
    Request.Url.Host.ToLower());
    return i;

    }

    public string GetLicense()
    {
    string XMLPath = Server.MapPath(PortalSettings.ApplicationPath) ;
    string XMLLicenseCode="0";

    string ConfigFile = XMLPath + "\\web.config";
    XmlDocument xDoc = new XmlDocument();
    xDoc.Load(ConfigFile);

    XmlNodeList ndLst;
    ndLst = xDoc.SelectNodes("//appSettings/add");

    foreach (XmlNode node in ndLst)
    {
    if (node.Attributes[0].Value == "LicenseNumber")
    {
    XMLLicenseCode = node.Attributes[1].Value ;
    break;
    }
    }
    return XMLLicenseCode;

    }

    public class Mydll
    {
    [DllImport("Licencontrol.dll" )]
    public static extern ushort LicenceApply(string LicenceName,
    string LicenceCode,string ProductGroupKey,
    uint ProductMagic,string AModifier);

    [DllImport("Licencontrol.dll")]
    public static extern ushort ReturnWSCount(string LicenceName,
    string LicenceCode, string ProductGroupKey,
    uint ProductMagic,string AModifier);

    [DllImport("Licencontrol.dll")]
    public static extern ushort InfoDemo(string LicenceName,
    string LicenceCode, string ProductGroupKey,
    uint ProductMagic,string AModifier);

    [DllImport("Licencontrol.dll")]
    public static extern string ExpireControl(string LicenceName,
    string LicenceCode, string ProductGroupKey,
    uint ProductMagic,string AModifier);

    }
    Tolga Guest

  2. Similar Questions and Discussions

    1. Error 403 Failed to read heders Error for long-runningCFMAIL and CFINDEX command
      I have two different pages with long-running scripts on which I am recieving the following error: Error - 403 Failed to read headers to server:...
    2. dllimport and web services
      I have an C#/ASP.Net 1.1 Web Service that has an exposed Web Method that uses an unmanaged DLL via the DllImport Attribute. Is one copy of the DLL...
    3. DllImport to unmanaged
      Hello NG From a Web Project (C#, XP-box) I want to call unmanaged code : so private static extern int FirstFunc(); BUT when I in my...
    4. dllimport call in aspnet application makes the application hangs
      As our application design requires us to use one of the validation API engine which was written on C(so basically all I have is a dll) and I tested...
    5. DllImport and WebMethod and STAThread
      I'm trying to use a 3rd party DLL, which I have no control over, in my WebService (written in C#). However, every time my WebService tries to call...
  3. #2

    Default Re: DllImport Error

    Hi folks!
    if u couldnt solve the problem or maybe i couldnt explain it :)...But
    it is not a shame to reply anything about it...

    [email]tetci@pyazilim.com[/email] (Tolga) wrote in message news:<bbcc45b3.0408310514.77f9470d@posting.google. com>...
    > Hello friends,
    > I need to load an unmanaged dll(which i wrote for license control)
    > from system32 folder and then my asp. net project will read the values
    > from there.(I'll write the full code to the bottom)
    >
    > I get an "Object reference is not set an instance of an object
    > error"...This code works in my local machine , but in our remote
    > machine there was a problem that i told above. I can only fix the
    > problem by iisreset , but problem repeats again and again for a while
    > later... The problem is in DLL Import section... full code is here
    > where it broke...
    > i am sure u can help me to solve this problem thanx everybody...
    >
    > private int CheckLicenceApply()
    > {
    > PortalSettings portalSettings =
    > (PortalSettings) HttpContext.Current.Items
    > ["PortalSettings"];
    >
    > int i= 0;
    > // error is in here when trying to load dll
    > i = Mydll.LicenceApply
    > (portalSettings.PortalTitle,GetLicense().ToString( ) ,
    > ProductGroupKey, ProductMagic,
    > Request.Url.Host.ToLower());
    > return i;
    >
    > }
    >
    > public string GetLicense()
    > {
    > string XMLPath = Server.MapPath(PortalSettings.ApplicationPath) ;
    > string XMLLicenseCode="0";
    >
    > string ConfigFile = XMLPath + "\\web.config";
    > XmlDocument xDoc = new XmlDocument();
    > xDoc.Load(ConfigFile);
    >
    > XmlNodeList ndLst;
    > ndLst = xDoc.SelectNodes("//appSettings/add");
    >
    > foreach (XmlNode node in ndLst)
    > {
    > if (node.Attributes[0].Value == "LicenseNumber")
    > {
    > XMLLicenseCode = node.Attributes[1].Value ;
    > break;
    > }
    > }
    > return XMLLicenseCode;
    >
    > }
    >
    > public class Mydll
    > {
    > [DllImport("Licencontrol.dll" )]
    > public static extern ushort LicenceApply(string LicenceName,
    > string LicenceCode,string ProductGroupKey,
    > uint ProductMagic,string AModifier);
    >
    > [DllImport("Licencontrol.dll")]
    > public static extern ushort ReturnWSCount(string LicenceName,
    > string LicenceCode, string ProductGroupKey,
    > uint ProductMagic,string AModifier);
    >
    > [DllImport("Licencontrol.dll")]
    > public static extern ushort InfoDemo(string LicenceName,
    > string LicenceCode, string ProductGroupKey,
    > uint ProductMagic,string AModifier);
    >
    > [DllImport("Licencontrol.dll")]
    > public static extern string ExpireControl(string LicenceName,
    > string LicenceCode, string ProductGroupKey,
    > uint ProductMagic,string AModifier);
    >
    > }
    Tolga Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139