none
Problem with getting PHP to instantiate .NET object RRS feed

  • Question

  • I'm trying to use the SerialPort class via PHP's DOTNET function thus:

    $serial = new DOTNET('System', 'System.IO.Ports.SerialPort');

    This says:

    PHP Fatal error:  Uncaught exception 'com_exception' with message 'Failed to instantiate .Net object [CreateInstance] [0x80070002] The system cannot find the file specified.

    It seems that PHP does not work with .NET 4 but I also have 2.0, 3.0 and 3.5 installed on my windows 7 64-bit system, as shown by this dotnet verifier log file

    PHP manual says that I have to use a fully qualified class name with the DOTNET function which they illustrate thusly:

     
    $full_assembly_string = 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a8425bc35256e463';
    $full_class_name = 'System.Windows.Forms.Form';
    $form = new DOTNET($full_assembly_string, $full_class_name);

    My problem is that, knowing nothing about .NET, I don't know what the fully qualified class name for System.IO.Ports.SerialPort should be in its .NET 2.0 form. Can anyone help with that?

    BTW: I'm using PHP 5.3.6 as a 32-bit application and as a command line utility rather than part of a web server.

    • Edited by PeterFacey Sunday, July 14, 2013 10:41 AM
    Sunday, July 14, 2013 10:36 AM

All replies

  • Per the example you cited, try something like this:

    $serial = new DOTNET('System.IO.Ports, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a8425bc35256e463', 'System.IO.Ports.SerialPort');

    I cannot guarantee the public key token is correct, but you do need to specify the .NET version as above.

    Monday, July 15, 2013 5:29 PM
  • Thanks. I just tried this and it gives the same error.

    Re. the public key token, I cannot find that token in dotnet verifier's log file (linked to in my OP). I'm wondering if it is just that token that is wrong. Can you help by telling me what file I should be looking for in that log file, please?

    I thought it might possibly be this one:

    [07/14/13,11:07:37] File C:\Windows\Assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll (version 2.0.50727.5467) is installed on the system

    but sadly that also gives the same error.

    Monday, July 15, 2013 5:49 PM
  • Sorry to say I have no further suggestions for you, as I'm PHP ignorant.

    I did find this while searching. The discussion may be helpful:

    http://php.net/manual/en/class.dotnet.php

    As your issue is about using the PHP DOTNET class, I suggest you find a suitable PHP forum.

    Tuesday, July 16, 2013 1:47 PM
  • Thanks for trying anyway. There might be a php problem, but the reason I posted here is because I was trying to find out where System.IO.Ports is on my system, so I can be sure I am referring to the correct .NET thing. I had thought that someone who understood .NET could read the verifier log file linked from my OP and easily see which file or assembly or whatever it is (I know nothing about .NET), and hence what public key token etc. is required.
    Tuesday, July 16, 2013 1:54 PM
  • By suggesting a PHP forum, I was hoping that PHP experts might help with the details of using the DOTNET function. I don't think it's a PHP problem per se, but there may be "tricks" in connection with using that function that PHP experts would know.

    I believe I provided the correct "path" to the .NET class you want to instantiate (System.IO.Ports), and the article I linked discusses how to find public keys in C:\Windows\Assembly.

    Hopefully somebody else here with PHP knowledge can assist.

    Tuesday, July 16, 2013 2:09 PM
  • How difficult can it be for someone to read the dot net verifier log file in my OP and tell me exactly where System.IO.Ports is on my system and what its public key token is? You don't need to know anything about php to do this. Alternatively, tell me how I find out this info for myself please.

    On the separate track, I have tried the main php developer forum but no one there is interested.

    Thursday, August 1, 2013 7:48 PM
  • The problem lies in the the Version Compatibility of PHP Extension php_dotnet.dll and the PHP.exe. 

    I did my best since last few days to read serial port usin dotnet route as well as php_dio.dll route. Believe me, its always a dead end. The php_dio.dll will hide the COM port from everybody and php_dotnet will not behave the way desired when used with PHP.

    Seems like Rest of the world is bycotting MS windows and shifting to Java, JS, Node, js, python, what not all sh..t. But Nothing better than MS. 

    However, integrating PHP with MS Libraries is near impossible. If anyone makes it through, I will be happy to learn. Thank you. All the best.


    • Edited by RakLali Tuesday, November 15, 2016 8:48 AM
    Tuesday, November 15, 2016 8:47 AM
  • Yes my OP was three years ago. I just used C++ in the end.
    Tuesday, November 15, 2016 10:45 AM
  • Dear Peter, Is it possible to know how you managed to integrate C++ with PHP. I need to learn desperately.

    Thank you sir.

    Tuesday, November 15, 2016 4:59 PM
  • Sorry, no. I just abandoned the idea of using PHP in favour of C++.
    Tuesday, November 15, 2016 6:32 PM