dougong8012 2012-04-18 14:06
浏览 66
已采纳

PHP DOTNET地狱

I'm quite a newbie in PHP and today I discovered DOTNET class.
So I studied manual, surfed the web to find some example and finally wrote my test app:

  1. Created a new DLL using Framework 4.0 Client Profile
  2. Signed the assembly with a strong name key
  3. Marked assembly as COM-Visible

This is the test code I wrote

using System;

namespace CSharpCOM
{
    public class CSharpCOMClass
    {
        public string Base64(string s)
        {
            return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(s));
        }
    }
}

I compiled the assembly and then registered in GAC (gacutil /if fullpath\CSharpCOM.dll).
If I use gacutil /l CSharpCOM I see

La cache di assembly globale contiene gli assembly seguenti:
csharpcom, Version=1.0.0.0, Culture=neutral, PublicKeyToken=beb607ae770f5750, processorArchitecture=MSIL

Numero di elementi = 1

So everything seems ok.
Then wrote this basic php:

<?php
try{
    $csclass = new DOTNET("CSharpCOM, Version=1.0.0.0, Culture=neutral, " .
                          "PublicKeyToken=beb607ae770f5750",
                          "CSharpCOM.CSharpCOMClass");
    echo $csclass->Base64("Test string"),"
";
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "
";
}
?>

Whatever I try, loading page hosted in Apache (http://localhost/test01/dotnet.php) I always get

Caught exception: Failed to instantiate .Net object [CreateInstance] [0x80070002] Impossibile trovare il file specificato.
Translation could be: unable to find specified file

Just another thing: using some example (a very basic one here) I read that my assembly (when registered) should be found on %windir%\assembly, but I'm only able to find it in %windi%\Microsoft.NET\assembly\GAC_MSIL\CSharpCOM\v4.0_1.0.0.0__beb607ae770f5750: is this correct? Why don't I have it on first directory?

More: if I create another framework project and try to add a .NET reference I can't find my assembly: is this related to the fact I'm not able to load this assembly from PHP?

Last note: I tried it on Windows XP Professional SP3 32bit and on Windows Seven Enterprise 64bit

UPDATE:
This works:

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

but this one does not:

$form = new DOTNET('System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089', 'System.Windows.Forms.Form');`  

Is it possible that PHP can load only framework 2.0 assemblies?

  • 写回答

2条回答 默认 最新

  • dqx24298 2012-04-18 14:50
    关注

    According to this bug report the DOTNET class is not loading .NET 4.0 DLLs. If you're not using any of the new libraries in .NET 4.0 you can target your to .NET 3.5 or lower by opening the project properties and on the "Application" tab change the "Target framework" to ".NET Framework 3.5 Client Profile"

    Now when you install your DLL into the GAC it will get installed into the CLR 2.0 GAC and should be able to be loaded using the DOTNET class in PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)