php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #29800 new DOTNET fails for assemblys other than mscorlib
Submitted: 2004-08-23 17:46 UTC Modified: 2019-10-21 07:43 UTC
Votes:7
Avg. Score:4.1 ± 1.4
Reproduced:7 of 7 (100.0%)
Same Version:5 (71.4%)
Same OS:4 (57.1%)
From: christian at wenz dot org Assigned: cmb (profile)
Status: Closed Package: COM related
PHP Version: 5.0.1 OS: WinXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: christian at wenz dot org
New email:
PHP Version: OS:

 

 [2004-08-23 17:46 UTC] christian at wenz dot org
Description:
------------
The .NET sample from the manual (stack, Pop(), Push()) works fine with the new patch, however I encounter problems instanciating .NET objects that are _not_ in mscorlib. I don't think there is an error in my code. 

Reproduce code:
---------------
<?php
  $dotnetxsl = new DOTNET("System.Xml", "System.Xml.Xsl.XslTransform");
?>

Expected result:
----------------
no output

Actual result:
--------------
Fatal error: Uncaught exception 'com_exception' with message 'Failed to instantiate .Net object' in e:\Inetpub\wwwroot\php\dotnet1.php:2 Stack trace: #0 {main} thrown in e:\Inetpub\wwwroot\php\dotnet1.php on line 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-09 06:45 UTC] wez@php.net
Hey Christian,

You probably need to fully qualify the assembly name to get it working.

Here's a non-working example; the assembly is loaded but object unwrapping doesn't give us an IDispatch'able handle, so instantiation fails.

Don't ask me how you determine the version and key tokens; I pulled these out of a decompiled .tlb file :-/

$f = new DOTNET('System.Windows.Forms,Version=1.0.5000.0,Culture=neutral,PublicKeyToken=b77a5c561934e089', 'System.Windows.Forms.Form');

PS: the next HEAD snapshot will contain better startup and error reporting for these things; possibly fixing that other  .net bug you reported a little while back.

 [2004-10-17 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2008-12-10 19:42 UTC] vince at siol dot net
Description:
---------------
As far as I can tell this bug is still present in 5.2.6. Using a fully qualified assembly name reproduces a different error, so it might be a step closer to working. 


Reproduce code:
---------------
$object = new DOTNET( 'System,Version=2.0.0.0,Culture=neutral,PublicKeyToken=B77A5C561934E089', 'System.Diagnostics.Process' );


Expected result:
----------------
- no output --


Actual result:
---------------
PHP Fatal error:  Uncaught exception 'com_exception' with message 'Failed to instantiate .Net object [Unwrapped, QI for IDispatch] [0x80004002] No such interface supported
'
 [2012-01-30 10:48 UTC] bszabolcs at gmail dot com
This bug is still present in PHP 5.3.8.

Here is the code I tried to use:

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

The error message:

Fatal error: Uncaught exception 'com_exception' with message 'Failed to 
instantiate .Net object [Unwrapped, QI for IDispatch] [0x80004002] No such 
interface supported '
 [2012-01-30 11:05 UTC] aharvey@php.net
Reopening per the last two comments, although I suspect this is firmly in the 
"patches welcome" category.
 [2012-01-30 11:05 UTC] aharvey@php.net
-Status: No Feedback +Status: Open
 [2012-01-30 11:10 UTC] bszabolcs at gmail dot com
Strange... the first works, the second gives that exception:

$fm = new DOTNET('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089', 'System.Windows.Forms.Form');

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

Both are with fully qualifie assembly name... 
Is there any way to activate more detailed debugging informations to see what is 
happening in background?
 [2013-10-21 01:28 UTC] kevin dot kenny at zygonia dot net
I think the problem here is that you can only instantiate .NET classes where they're decorated with the ComVisible(true) attribute.

For example in the documentation sample code here:

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

The System.Collections.Stack class is decorated with this attribute:

http://msdn.microsoft.com/en-us/library/system.collections.stack.aspx

As is the System.Windows.Forms.Form class example earlier in this bug report.

However if one tries to instantiate a .NET class without this attribute such as System.Xml.XmlDocument:

http://msdn.microsoft.com/en-us/library/system.xml.xmldocument

Then an exception is thrown:

$xml = new DOTNET('System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089', 'System.Xml.XmlDocument');

Produces:

PHP Fatal error:  Uncaught exception 'com_exception' with message 'Failed to instantiate .Net object [Unwrapped, QI for IDispatch] [0x80004002] No such interface supported

These are my findings from working with .NET 2.0. There seems to be additional problems with instantiating .NET 4 classes because of changes in the way the GAC is used (or not).
 [2019-10-21 07:34 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2019-10-21 07:34 UTC] cmb@php.net
Indeed it is like kevin dot kenny said: .NET classes have to be
visible to COM.  Changing to documentation issue.
 [2019-10-21 07:35 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2019-10-21 07:43 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=348193
Log: Fix #29800: new DOTNET fails for assemblys other than mscorlib
 [2019-10-21 07:43 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2019-10-21 07:43 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2019-10-21 07:45 UTC] salathe@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=d577dafb05cc2dab28ac1eece267ba15ed552e1f
Log: Fix #29800: new DOTNET fails for assemblys other than mscorlib
 [2020-02-07 06:04 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=c5918c68ff9f0fd392cee31b59be851a0783884a
Log: Fix #29800: new DOTNET fails for assemblys other than mscorlib
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC