2011-08-15 22 views
1

我在PHP腳本中使用DOTNET類指一個ASP.NET裝配指asp.net的dll到PHP

$test = new DOTNET('assemblyname','classname'); 

我得到一個致命錯誤,運行此腳本時。

致命錯誤:

Uncaught exception 'com_exception' with message 'Failed to instantiate .Net object [CreateInstance] [0x80131513] ' in C:\Program Files\xampplite\htdocs\xampp\phptest.php:2 Stack trace: #0 C:\Program Files\xampplite\htdocs\xampp\phptest.php(2): dotnet->dotnet('EncryptDecrypt,...', 'EncryptDecrypt....') #1 {main} thrown in C:\Program Files\xampplite\htdocs\xampp\phptest.php on line 2

任何幫助?

+0

能否請您發佈全堆棧跟蹤完整的錯誤消息? – gyurisc

+0

你能否也請在PHP代碼中發佈實際的方法調用? – gyurisc

回答

1

我認爲這正在發生的事情,因爲無論你的庫未在GAC發現不強命名或沒有標記有ComVisible特性。

爲了使標記有ComVisible特性,確保AssemblyInfo.cs中是這樣的:

[組件:標記有ComVisible特性(真)]

對於強名稱,並在GAC安裝它,我發現這個職位:

For strongly-named NET assemblies that are registered in the GAC, you can just use the assembly name e.g: $x = new DOTNET ("myAssembly", "myClass");

For strongly-named NET assemblies that aren't registered in the GAC, you need to use the full assembly string e.g. $x = new DOTNET('myAssembly, Version=X.X.X.X, Culture=neutral, PublicKeyToken=ZZZZZZZZZZZZ', 'myClass');

You can't instantiate assemblies that haven't been strongly named.

"Strongly named" means that the assembly has a public key. To strongly name your own classes in Visual Studio, go to the Signing tab in the project properties and click the 'sign the assembly' box and choose a key file name.

To register an assembly in the GAC, there are various tools around to do that, but the easiest method is to drag-and-drop the compiled assembly into c:\windows\assembly using windows explorer (a shell extension is installed by default that handles registering dragged files).

來源:PHP: DOTNET - Manual

+0

是的,我曾嘗試拖動文件到海關總署,也給予了版本,PublicKeyToken.I我得到同樣的致命錯誤,如上面提到的。 ? – Sparton

+0

我的PHP代碼: methodname(「1356」); echo $ test; ?> – Sparton

+0

也許這是我在這裏最愚蠢的觀察,但的AssemblyName應該像中是指mylib.dll。我懷疑在你的真實項目中,你的PHP方法調用中有確切的.net庫名稱。首先,我會嘗試打電話給一些知名圖書館的一些衆所周知的方法(例如mscorlib.dll中Console.WriteLine),看看問題是否與你的PHP代碼或與您的.NET。如果呼叫經過比PHP是好的,問題是你的.NET庫 – gyurisc