PHP DOTNET地狱地狱、PHP、DOTNET

2023-09-04 00:40:02 作者:~美人泪*无人能懂~

我在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:

在创建使用Framework 4.0客户端配置文件中的新的DLL 签订组装强名称密钥 标记组件作为COM可见

这是考验code我写了

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));
        }
    }
}

我编的程序集,然后在GAC注册的( GACUTIL /如果完整路径\ CSharpCOM.dll )。 如果我使用 GACUTIL / L CSharpCOM 我看

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

香格里拉缓存迪组装globale contiene GLI装配seguenti:   csharpcom,版本= 1.0.0.0,文化=中立,   公钥= beb607ae770f5750,的ProcessorArchitecture = MSIL

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

NUMERO二ELEMENTI = 1

Numero di elementi = 1

所以,一切似乎确定。 然后写了这个基本的PHP:

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"),"\n";
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
?>

无论我尝试,托管在Apache中加载页面(的http://localhost/test01/dotnet.php )我总是得到

捕捉到异常:无法实例化.NET对象[的CreateInstance]   [0x80070002] Impossibile trovare IL文件specificato。   翻译可以是:找不到指定文件

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

只是另一件事:使用一些例子(一个非常基本的一个这里)我读了我的组装(注册时)应在%WINDIR%\组装被发现,但我只能找到它在%windi%\ Microsoft.NET \组装\ GAC_MSIL \ CSharpCOM \ v4.0_1.0.0.0__beb607ae770f5750 :这是正确的?我为什么不把它的第一个目录?

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?

更多:如果我创建另一个框架项目,并尝试添加.NET引用我无法找到我的组件:?这是关系到我无法从PHP加载该程序集的事实

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?

最后要注意的:我试了一下在Windows XP Professional SP3 32位和Windows 7的企业64

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

更新: 这工作: $形式=新DOTNET(System.Windows.Forms的,版本= 2.0.0.0,文化=中性公钥= b77a5c561934e089','System.Windows.Forms.Form中'); 但是这一次没有: $形式=新DOTNET(System.Windows.Forms的,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089','System.Windows.Forms.Form中'); 是否有可能PHP可以加载只Framework 2.0的组件?

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 no: $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?

推荐答案

根据这一错误报告该DOTNET类没有加载.NET 4.0的DLL。如果你不使用任何在.NET 4.0中的新库,你可以到.NET 3.5或更低打开项目属性,应用程序选项卡上改变目标框架,以.NET Framework 3.5的客户端针对您简介

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"

现在,当您安装您的DLL到GAC它会被安装到CLR 2.0 GAC,应该能够使用DOTNET类在PHP中加载。

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.