• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

.NET console app and DLL issue

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    .NET console app and DLL issue

    This is on Windows 2003 Server. I have an olde ASP script that runs a .NET console app (to get a price from a database) via WScript.Shell. The basic version that just returns a number works fine.

    However, the console app needs to connect to a MYSQL5 database, which means it links to the MySQL.Data DLL. The DLL is in the same folder as the EXE, but whenever I try it via the web it fails to find the DLL. I get a "Starting Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'MySql.Data, Version=6.2.2.0" etc. message back on stderr.

    However, if I run the same exe from a command prompt on the server it works fine. I've tried setting the PATH, and also checked that the webserver anonymous account has read access to the EXE and DLLs, so I can't understand why the version run from the command line works, and the version run via WScript.Shell fails.

    Can anybody help?

    (The problem here is it's a hodge podge of a system with ASP using MySQL4 and ASP .NET using MySQL5 otherwise I'd just write the ASP to talk to the database).
    Will work inside IR35. Or for food.

    #2
    It's likely to be a permissions problem - perhaps with another assembly this one references?.

    In the full exception text it should give you details on how to set the registry key which provides you with further details on which assemblies failed to load and where it looked.

    If you enable that and re-attempt you should get a better error for debugging. I haven't done it for quite a long time but I'm pretty sure it provides you with all the paths it attempts to access.

    Comment


      #3
      Thanks - it does indeed tell me where to turn on more verbose errors, but all I can really see is "Access is denied". Which probably means permissions somewhere, but it seems weird to me that it has permission to run the EXE but not load a DLL.

      Do I need an "application configuration file"?

      Starting Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. Access is denied. File name: 'MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' at GetPrice.Program.ConnectDatabase() at GetPrice.Program.Main(String[] args) === Pre-bind state information === LOG: User = Unknown LOG: DisplayName = MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d (Fully-specified) LOG: Appbase = file:///d:/inetpub/DWShop2/bin/ LOG: Initial PrivatePath = NULL Calling assembly : GetPrice, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. === LOG: This bind starts in default load context. LOG: No application configuration file found. LOG: Using machine configuration file from C:\WINNT\Microsoft.NET\Framework\v2.0.50727\config \machine.config. LOG: Post-policy reference: MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d LOG: Attempting download of new URL file:///d:/inetpub/DWShop2/bin/MySql.Data.DLL. ERR: Failed to complete setup of assembly (hr = 0x80070005). Probing terminated
      Will work inside IR35. Or for food.

      Comment


        #4
        Originally posted by VectraMan View Post
        Thanks - it does indeed tell me where to turn on more verbose errors, but all I can really see is "Access is denied". Which probably means permissions somewhere, but it seems weird to me that it has permission to run the EXE but not load a DLL.

        Do I need an "application configuration file"?
        No idea if this will help or not, but you could try running FUSLOGVW from a VS command prompt then running the app. With a bit of luck and a following wind this has a chance of telling exactly what it is trying to load, the dependencies and where it is trying to load them from.

        The assemblies will need to be in whatever the current working directory is when the app is launched from the shell.

        From the exception it appears that "d:/inetpub/DWShop2/bin/" is the application directory at time of trying to load. Is this where the assemblies are all located ?

        Bunging MySQL.DATA.DLL in the GAC might help.

        Comment


          #5
          Yes the assembly is in that folder, as is another ASP .NET app that uses it and works fine. I've tried adding the DLL to the GAC, and also moving the whole thing somewhere else.

          Can anyone think of a better solution? Basically I have an SHTML file with "#exec cgi="/new-bin/get_price2.asp?prod_id=1111" in it, that then runs the ASP which uses WScript.Shell to run the .NET console app. Is there a way of calling a .NET DLL from SHTML in a similar fashion and cut out a stage (though it'll still need to use MySQL and may fail in the same way)?
          Will work inside IR35. Or for food.

          Comment


            #6
            I solved my problem by doing it instead in ........... PHP.
            Will work inside IR35. Or for food.

            Comment

            Working...
            X