referring asp.net dll to php

1

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?

php
.net
asked on Stack Overflow Aug 15, 2011 by Sparton • edited Aug 15, 2011 by sll

1 Answer

1

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

answered on Stack Overflow Aug 15, 2011 by gyurisc

User contributions licensed under CC BY-SA 3.0