Call a C# .net .dll script using PHP












4















I have a C# .net dll script that calls a SQL stored procedure that SELECTs data in order to do run relevant methods.



I need to run the dll using PHP as my entire application is built in PHP.



What is the best way of doing this?



I'm not experienced at all with C#.



EDIT



I successfully registered the .net dll using:



RegAsm.exe DllName.dll /tlb:DllName.tlb


I should now be able to use PHP's COM() method as described below to call the dll's functions/methods.



But will these functions still be accessible through the COM() method as the .net dll was registered as an assembly? Does it make a difference?



EDIT



After registering the .net dll assembly I get an error message when I try to call the method using COM():



"PHP Fatal error:  Uncaught exception 'com_exception' with message 'Failed
to create COM object `DllName.ClassName': Invalid syntax"


EDIT



Tried using:



new DOTNET('DllName, Version=4.0.30319.33440, Culture=neutral,
PublicTokenKey=14843e0419858c21', 'ClassName');


got an internal server 500 error



Is this because PHP doesn't communicate with .net 4 assemblies?










share|improve this question




















  • 2





    best way is to convert the query to a PHP implementation. You could also use the exec() php function, but I think use of this code when the frontend isn't the shell is considered bad practice..

    – RichardBernards
    Nov 19 '14 at 12:09













  • I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.

    – proPhet
    Nov 19 '14 at 12:11











  • What do you mean by a C# script? C# is compiled into an exe or dll.

    – Ben Robinson
    Nov 19 '14 at 12:13











  • Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...

    – RichardBernards
    Nov 19 '14 at 12:13











  • the script is a .dll file

    – proPhet
    Nov 19 '14 at 12:14
















4















I have a C# .net dll script that calls a SQL stored procedure that SELECTs data in order to do run relevant methods.



I need to run the dll using PHP as my entire application is built in PHP.



What is the best way of doing this?



I'm not experienced at all with C#.



EDIT



I successfully registered the .net dll using:



RegAsm.exe DllName.dll /tlb:DllName.tlb


I should now be able to use PHP's COM() method as described below to call the dll's functions/methods.



But will these functions still be accessible through the COM() method as the .net dll was registered as an assembly? Does it make a difference?



EDIT



After registering the .net dll assembly I get an error message when I try to call the method using COM():



"PHP Fatal error:  Uncaught exception 'com_exception' with message 'Failed
to create COM object `DllName.ClassName': Invalid syntax"


EDIT



Tried using:



new DOTNET('DllName, Version=4.0.30319.33440, Culture=neutral,
PublicTokenKey=14843e0419858c21', 'ClassName');


got an internal server 500 error



Is this because PHP doesn't communicate with .net 4 assemblies?










share|improve this question




















  • 2





    best way is to convert the query to a PHP implementation. You could also use the exec() php function, but I think use of this code when the frontend isn't the shell is considered bad practice..

    – RichardBernards
    Nov 19 '14 at 12:09













  • I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.

    – proPhet
    Nov 19 '14 at 12:11











  • What do you mean by a C# script? C# is compiled into an exe or dll.

    – Ben Robinson
    Nov 19 '14 at 12:13











  • Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...

    – RichardBernards
    Nov 19 '14 at 12:13











  • the script is a .dll file

    – proPhet
    Nov 19 '14 at 12:14














4












4








4


1






I have a C# .net dll script that calls a SQL stored procedure that SELECTs data in order to do run relevant methods.



I need to run the dll using PHP as my entire application is built in PHP.



What is the best way of doing this?



I'm not experienced at all with C#.



EDIT



I successfully registered the .net dll using:



RegAsm.exe DllName.dll /tlb:DllName.tlb


I should now be able to use PHP's COM() method as described below to call the dll's functions/methods.



But will these functions still be accessible through the COM() method as the .net dll was registered as an assembly? Does it make a difference?



EDIT



After registering the .net dll assembly I get an error message when I try to call the method using COM():



"PHP Fatal error:  Uncaught exception 'com_exception' with message 'Failed
to create COM object `DllName.ClassName': Invalid syntax"


EDIT



Tried using:



new DOTNET('DllName, Version=4.0.30319.33440, Culture=neutral,
PublicTokenKey=14843e0419858c21', 'ClassName');


got an internal server 500 error



Is this because PHP doesn't communicate with .net 4 assemblies?










share|improve this question
















I have a C# .net dll script that calls a SQL stored procedure that SELECTs data in order to do run relevant methods.



I need to run the dll using PHP as my entire application is built in PHP.



What is the best way of doing this?



I'm not experienced at all with C#.



EDIT



I successfully registered the .net dll using:



RegAsm.exe DllName.dll /tlb:DllName.tlb


I should now be able to use PHP's COM() method as described below to call the dll's functions/methods.



But will these functions still be accessible through the COM() method as the .net dll was registered as an assembly? Does it make a difference?



EDIT



After registering the .net dll assembly I get an error message when I try to call the method using COM():



"PHP Fatal error:  Uncaught exception 'com_exception' with message 'Failed
to create COM object `DllName.ClassName': Invalid syntax"


EDIT



Tried using:



new DOTNET('DllName, Version=4.0.30319.33440, Culture=neutral,
PublicTokenKey=14843e0419858c21', 'ClassName');


got an internal server 500 error



Is this because PHP doesn't communicate with .net 4 assemblies?







c# php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '14 at 12:13







proPhet

















asked Nov 19 '14 at 12:08









proPhetproPhet

5232728




5232728








  • 2





    best way is to convert the query to a PHP implementation. You could also use the exec() php function, but I think use of this code when the frontend isn't the shell is considered bad practice..

    – RichardBernards
    Nov 19 '14 at 12:09













  • I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.

    – proPhet
    Nov 19 '14 at 12:11











  • What do you mean by a C# script? C# is compiled into an exe or dll.

    – Ben Robinson
    Nov 19 '14 at 12:13











  • Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...

    – RichardBernards
    Nov 19 '14 at 12:13











  • the script is a .dll file

    – proPhet
    Nov 19 '14 at 12:14














  • 2





    best way is to convert the query to a PHP implementation. You could also use the exec() php function, but I think use of this code when the frontend isn't the shell is considered bad practice..

    – RichardBernards
    Nov 19 '14 at 12:09













  • I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.

    – proPhet
    Nov 19 '14 at 12:11











  • What do you mean by a C# script? C# is compiled into an exe or dll.

    – Ben Robinson
    Nov 19 '14 at 12:13











  • Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...

    – RichardBernards
    Nov 19 '14 at 12:13











  • the script is a .dll file

    – proPhet
    Nov 19 '14 at 12:14








2




2





best way is to convert the query to a PHP implementation. You could also use the exec() php function, but I think use of this code when the frontend isn't the shell is considered bad practice..

– RichardBernards
Nov 19 '14 at 12:09







best way is to convert the query to a PHP implementation. You could also use the exec() php function, but I think use of this code when the frontend isn't the shell is considered bad practice..

– RichardBernards
Nov 19 '14 at 12:09















I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.

– proPhet
Nov 19 '14 at 12:11





I don't understand the C# language enough to convert to PHP. That was my first thought lol. But the script is greek to me and it seems like it's calling c# functions.

– proPhet
Nov 19 '14 at 12:11













What do you mean by a C# script? C# is compiled into an exe or dll.

– Ben Robinson
Nov 19 '14 at 12:13





What do you mean by a C# script? C# is compiled into an exe or dll.

– Ben Robinson
Nov 19 '14 at 12:13













Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...

– RichardBernards
Nov 19 '14 at 12:13





Somewhere, somehow the query should be deducted, but without sourcecode, we cannot give an accurate answer to this...

– RichardBernards
Nov 19 '14 at 12:13













the script is a .dll file

– proPhet
Nov 19 '14 at 12:14





the script is a .dll file

– proPhet
Nov 19 '14 at 12:14












2 Answers
2






active

oldest

votes


















2














Option 1: Use the DLL



You can call the function using PHP's COM class.



You'll need to be running PHP on Windows, which I assume you are if you're using a C# DLL.



Steps:




  1. Register the DLL using the command regasm yourdllname.dll in Command Prompt or the Run dialog.
    You have one RegAsm.exe for each version of .NET installed on your computer, so make sure to execute the one for the version of .NET that the DLL targets by running it from %windir%Microsoft.NETAppropriateVersion.

  2. Create a COM object in PHP that references the class name of the DLL.

  3. Call the function, which will be available as a method of the COM object you've created.


Example:



$object = new COM('MyDllProjectName.MyDllClassName');
$object->myMethod();


Option 2: Rewrite in PHP



As has been mentioned, the cleaner, cross-platform option is to re-implement the SQL query in PHP directly, especially if your only reason for using the DLL is to run a query.






share|improve this answer





















  • 4





    Option 3 Access the DLL through a webservice

    – DarkBee
    Nov 19 '14 at 12:45











  • I'm confused, where does the myMethod() come from? is it instantiated there? how then do I call it?

    – proPhet
    Nov 19 '14 at 13:27













  • You'd replace myMethod with the name of the method (function) that calls the SQL stored procedure in your DLL.

    – Eric Eskildsen
    Nov 19 '14 at 13:31











  • I tried registering the dll but I got an error saying that ..the-entry point DllRegisterServer was not found

    – proPhet
    Nov 19 '14 at 14:13






  • 1





    Try using regasm (C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead of regsvr32. The syntax is the same: regasm yourdllname.dll.

    – Eric Eskildsen
    Nov 19 '14 at 14:28



















1














Using COM directly has many caveats and issues.



There is a library called NetPhp that abstracts on top of COM using reflection, so that you can call ANY .dll from within PHP without hassle:



http://www.drupalonwindows.com/en/blog/calling-net-framework-and-net-assemblies-php






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27016470%2fcall-a-c-sharp-net-dll-script-using-php%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Option 1: Use the DLL



    You can call the function using PHP's COM class.



    You'll need to be running PHP on Windows, which I assume you are if you're using a C# DLL.



    Steps:




    1. Register the DLL using the command regasm yourdllname.dll in Command Prompt or the Run dialog.
      You have one RegAsm.exe for each version of .NET installed on your computer, so make sure to execute the one for the version of .NET that the DLL targets by running it from %windir%Microsoft.NETAppropriateVersion.

    2. Create a COM object in PHP that references the class name of the DLL.

    3. Call the function, which will be available as a method of the COM object you've created.


    Example:



    $object = new COM('MyDllProjectName.MyDllClassName');
    $object->myMethod();


    Option 2: Rewrite in PHP



    As has been mentioned, the cleaner, cross-platform option is to re-implement the SQL query in PHP directly, especially if your only reason for using the DLL is to run a query.






    share|improve this answer





















    • 4





      Option 3 Access the DLL through a webservice

      – DarkBee
      Nov 19 '14 at 12:45











    • I'm confused, where does the myMethod() come from? is it instantiated there? how then do I call it?

      – proPhet
      Nov 19 '14 at 13:27













    • You'd replace myMethod with the name of the method (function) that calls the SQL stored procedure in your DLL.

      – Eric Eskildsen
      Nov 19 '14 at 13:31











    • I tried registering the dll but I got an error saying that ..the-entry point DllRegisterServer was not found

      – proPhet
      Nov 19 '14 at 14:13






    • 1





      Try using regasm (C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead of regsvr32. The syntax is the same: regasm yourdllname.dll.

      – Eric Eskildsen
      Nov 19 '14 at 14:28
















    2














    Option 1: Use the DLL



    You can call the function using PHP's COM class.



    You'll need to be running PHP on Windows, which I assume you are if you're using a C# DLL.



    Steps:




    1. Register the DLL using the command regasm yourdllname.dll in Command Prompt or the Run dialog.
      You have one RegAsm.exe for each version of .NET installed on your computer, so make sure to execute the one for the version of .NET that the DLL targets by running it from %windir%Microsoft.NETAppropriateVersion.

    2. Create a COM object in PHP that references the class name of the DLL.

    3. Call the function, which will be available as a method of the COM object you've created.


    Example:



    $object = new COM('MyDllProjectName.MyDllClassName');
    $object->myMethod();


    Option 2: Rewrite in PHP



    As has been mentioned, the cleaner, cross-platform option is to re-implement the SQL query in PHP directly, especially if your only reason for using the DLL is to run a query.






    share|improve this answer





















    • 4





      Option 3 Access the DLL through a webservice

      – DarkBee
      Nov 19 '14 at 12:45











    • I'm confused, where does the myMethod() come from? is it instantiated there? how then do I call it?

      – proPhet
      Nov 19 '14 at 13:27













    • You'd replace myMethod with the name of the method (function) that calls the SQL stored procedure in your DLL.

      – Eric Eskildsen
      Nov 19 '14 at 13:31











    • I tried registering the dll but I got an error saying that ..the-entry point DllRegisterServer was not found

      – proPhet
      Nov 19 '14 at 14:13






    • 1





      Try using regasm (C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead of regsvr32. The syntax is the same: regasm yourdllname.dll.

      – Eric Eskildsen
      Nov 19 '14 at 14:28














    2












    2








    2







    Option 1: Use the DLL



    You can call the function using PHP's COM class.



    You'll need to be running PHP on Windows, which I assume you are if you're using a C# DLL.



    Steps:




    1. Register the DLL using the command regasm yourdllname.dll in Command Prompt or the Run dialog.
      You have one RegAsm.exe for each version of .NET installed on your computer, so make sure to execute the one for the version of .NET that the DLL targets by running it from %windir%Microsoft.NETAppropriateVersion.

    2. Create a COM object in PHP that references the class name of the DLL.

    3. Call the function, which will be available as a method of the COM object you've created.


    Example:



    $object = new COM('MyDllProjectName.MyDllClassName');
    $object->myMethod();


    Option 2: Rewrite in PHP



    As has been mentioned, the cleaner, cross-platform option is to re-implement the SQL query in PHP directly, especially if your only reason for using the DLL is to run a query.






    share|improve this answer















    Option 1: Use the DLL



    You can call the function using PHP's COM class.



    You'll need to be running PHP on Windows, which I assume you are if you're using a C# DLL.



    Steps:




    1. Register the DLL using the command regasm yourdllname.dll in Command Prompt or the Run dialog.
      You have one RegAsm.exe for each version of .NET installed on your computer, so make sure to execute the one for the version of .NET that the DLL targets by running it from %windir%Microsoft.NETAppropriateVersion.

    2. Create a COM object in PHP that references the class name of the DLL.

    3. Call the function, which will be available as a method of the COM object you've created.


    Example:



    $object = new COM('MyDllProjectName.MyDllClassName');
    $object->myMethod();


    Option 2: Rewrite in PHP



    As has been mentioned, the cleaner, cross-platform option is to re-implement the SQL query in PHP directly, especially if your only reason for using the DLL is to run a query.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Oct 17 '18 at 19:33

























    answered Nov 19 '14 at 12:42









    Eric EskildsenEric Eskildsen

    1,08811327




    1,08811327








    • 4





      Option 3 Access the DLL through a webservice

      – DarkBee
      Nov 19 '14 at 12:45











    • I'm confused, where does the myMethod() come from? is it instantiated there? how then do I call it?

      – proPhet
      Nov 19 '14 at 13:27













    • You'd replace myMethod with the name of the method (function) that calls the SQL stored procedure in your DLL.

      – Eric Eskildsen
      Nov 19 '14 at 13:31











    • I tried registering the dll but I got an error saying that ..the-entry point DllRegisterServer was not found

      – proPhet
      Nov 19 '14 at 14:13






    • 1





      Try using regasm (C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead of regsvr32. The syntax is the same: regasm yourdllname.dll.

      – Eric Eskildsen
      Nov 19 '14 at 14:28














    • 4





      Option 3 Access the DLL through a webservice

      – DarkBee
      Nov 19 '14 at 12:45











    • I'm confused, where does the myMethod() come from? is it instantiated there? how then do I call it?

      – proPhet
      Nov 19 '14 at 13:27













    • You'd replace myMethod with the name of the method (function) that calls the SQL stored procedure in your DLL.

      – Eric Eskildsen
      Nov 19 '14 at 13:31











    • I tried registering the dll but I got an error saying that ..the-entry point DllRegisterServer was not found

      – proPhet
      Nov 19 '14 at 14:13






    • 1





      Try using regasm (C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead of regsvr32. The syntax is the same: regasm yourdllname.dll.

      – Eric Eskildsen
      Nov 19 '14 at 14:28








    4




    4





    Option 3 Access the DLL through a webservice

    – DarkBee
    Nov 19 '14 at 12:45





    Option 3 Access the DLL through a webservice

    – DarkBee
    Nov 19 '14 at 12:45













    I'm confused, where does the myMethod() come from? is it instantiated there? how then do I call it?

    – proPhet
    Nov 19 '14 at 13:27







    I'm confused, where does the myMethod() come from? is it instantiated there? how then do I call it?

    – proPhet
    Nov 19 '14 at 13:27















    You'd replace myMethod with the name of the method (function) that calls the SQL stored procedure in your DLL.

    – Eric Eskildsen
    Nov 19 '14 at 13:31





    You'd replace myMethod with the name of the method (function) that calls the SQL stored procedure in your DLL.

    – Eric Eskildsen
    Nov 19 '14 at 13:31













    I tried registering the dll but I got an error saying that ..the-entry point DllRegisterServer was not found

    – proPhet
    Nov 19 '14 at 14:13





    I tried registering the dll but I got an error saying that ..the-entry point DllRegisterServer was not found

    – proPhet
    Nov 19 '14 at 14:13




    1




    1





    Try using regasm (C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead of regsvr32. The syntax is the same: regasm yourdllname.dll.

    – Eric Eskildsen
    Nov 19 '14 at 14:28





    Try using regasm (C:WindowsMicrosoft.NETFrameworkYourVersionRegAsm.exe) instead of regsvr32. The syntax is the same: regasm yourdllname.dll.

    – Eric Eskildsen
    Nov 19 '14 at 14:28













    1














    Using COM directly has many caveats and issues.



    There is a library called NetPhp that abstracts on top of COM using reflection, so that you can call ANY .dll from within PHP without hassle:



    http://www.drupalonwindows.com/en/blog/calling-net-framework-and-net-assemblies-php






    share|improve this answer




























      1














      Using COM directly has many caveats and issues.



      There is a library called NetPhp that abstracts on top of COM using reflection, so that you can call ANY .dll from within PHP without hassle:



      http://www.drupalonwindows.com/en/blog/calling-net-framework-and-net-assemblies-php






      share|improve this answer


























        1












        1








        1







        Using COM directly has many caveats and issues.



        There is a library called NetPhp that abstracts on top of COM using reflection, so that you can call ANY .dll from within PHP without hassle:



        http://www.drupalonwindows.com/en/blog/calling-net-framework-and-net-assemblies-php






        share|improve this answer













        Using COM directly has many caveats and issues.



        There is a library called NetPhp that abstracts on top of COM using reflection, so that you can call ANY .dll from within PHP without hassle:



        http://www.drupalonwindows.com/en/blog/calling-net-framework-and-net-assemblies-php







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 5 '17 at 19:40









        daviddavid

        111




        111






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27016470%2fcall-a-c-sharp-net-dll-script-using-php%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            Npm cannot find a required file even through it is in the searched directory