douti6740 2011-08-15 08:56
浏览 29

将asp.net dll引用到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?

  • 写回答

1条回答 默认 最新

  • dqxz96998 2011-08-15 09:08
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法