开发者

referring asp.net dll to php

I am referring a ASP.NET assembly in php script using DotNet class

i.e.

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

I am getting a fatal error while running this script.

Fatal error:

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

Any help on this?


I think this is happening because either your library is not found in the GAC and not strong named or not COMVisible.

For making COMVisible, make sure that AssemblyInfo.cs is like this:

[assembly: ComVisible(true)]

For strong names and installing it in the GAC, I found this post:

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).

Source: PHP: DOTNET - Manual

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜