没有注册类从PHP错误 [英] Class not registered error from PHP

查看:412
本文介绍了没有注册类从PHP错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经创建了一个C#类的库程序集,并使其COM可见能够从PHP调用它的方法。这用来做工精细,但现在我们想在Windows Server 2008服务器上安装它,我们继续走成类未注册的错误。

We've created a C# class library assembly and made it COM visible to be able to call its methods from PHP. This used to work fine, but now we wanted to install it on a Windows Server 2008 server and we keep walking into the error "Class not registered".

要排除任何依赖问题我在C#中做了一个小小的测试类库。该类库是专为任何CPU,它是COM可见(也AssemblyInfo.cs中设置标记有ComVisible特性为true)。测试类库只包含一个方法,一个类。该类称为TESTLIB和命名空间也被称为TESTLIB。该方法被称为测试,只返回一个字符串

To rule out any dependency problems I made a tiny little test class library in C#. The class library is built for Any CPU and it is COM visible (also set COMVisible to true in AssemblyInfo.cs). The test class library only contains one class with one method. The class is called TestLib and the namespace is also called TestLib. The method is called Test and only returns a string.

我们所做的是以下内容:
- 建成TestLib.dll
- 复制它为Windows Server 2008计算机
- 注册的DLL:regasm /基本代码TestLib.dll
- 在regasm工具返回成功消息
- 在PHP中,我们只是尝试创建一个新的COM例如:

What we have done is the following: - built the TestLib.dll - copied it to the Windows Server 2008 machine - registered the dll with: regasm /codebase TestLib.dll - the regasm tool returns a success message - in PHP we simply try to create a new COM instance:

try
{
   $test = new COM("TestLib.TestLib");
}
catch (Exception $e)
{
   die($e->getMessage());
}




  • 当我们调用这个测试脚本来寻浏览器或命令行(PHP -f test.php的),我们得到的错误在这两种情况下未注册的类

  • 我也试过加入TESTLIB到GAC通过GACUTIL -i,但无济于事;仍然类没有注册的错误。

    I also tried adding TestLib to the GAC by using gacutil -i, but to no avail; still the class not registered error.

    然后我试图编译testlibrary与.NET 2.0,而不是4.0作为目标框架,同样的结果。 NET框架4.0安装的方式在服务器上。

    Then I tried compiling the testlibrary with .NET 2.0 instead of 4.0 as the target framework, same result. The .NET framework 4.0 is installed on the server by the way.

    任何想法?

    推荐答案

    好了,经过一番更多的研究,我理解了它。 php.exe文件过程是32位。在COM可见汇编的编译所有CPU所以它应该是既32位和64位应用程序访问。

    Okay, so after some more research I figured it out. The php.exe process is 32 bit. The COM visible assembly is compiled for Any CPU so it should be accessible to both 32 and 64 bit applications.

    的问题是,在64位操作系统的php.exe,和任何与此有关的32位过程中,搜索在HKEY_CLASSES_ROOT\Wow6432Node\CLSID的HKEY_CLASSES_ROOT\CLSID和HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID,而不是代替HKEY_LOCAL_MACHINE\Software\Classes\ CLSID。不被附带.NET框架v4的Windows Server 2008上在Windows 7上创建它们regasm创造了Wow6432键的注册表项,不要问我为什么。

    The problem is that on a 64 bit OS php.exe, and any 32 bit process for that matter, searches in HKEY_CLASSES_ROOT\Wow6432Node\CLSID instead of HKEY_CLASSES_ROOT\CLSID and in HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID instead of HKEY_LOCAL_MACHINE\Software\Classes\CLSID. The registry entries in the Wow6432 keys aren't created by regasm that is shipped with .NET framework v4 on Windows Server 2008. On Windows 7 they are created, don't ask me why.

    这也证明了,如果我创建.NET v2.0的一个小测试组件和regasm注册它附带的.NET framework 2.0,它确实造成Windows 2008上的怪项Wow6432Node。

    It also turned out that if I create a little test assembly for .NET v2.0 and register it with regasm that ships with .NET framework v2.0 that it does create the Wow6432Node entries on Windows 2008. Strange.

    所以我的解决方法是使用来在服务器上创建一个基本的注册表文件:

    So my solution is to create a basic registry file on the server using:

    regasm /regfile MyClassLib.dll
    

    这将创建一个文件MyClassLib.reg只用正常'的64位条目。然后,我从Windows 7的计算机导出的Wow6432Node密钥并将其添加到该.reg文件。现在,当我导入reg文件导入注册表在Windows 2008上的一切工作正常。

    This creates a file MyClassLib.reg with only the 'normal' 64 bit entries. Then I exported the Wow6432Node keys from a Windows 7 machine and added it to that .reg file. Now when I import that reg file into the registry on Windows 2008 everything works fine.

    有关的Wow6432Node条目的更多信息请查看:的 http://msdn.microsoft.com/en-us/library /windows/desktop/ms724072%28v=vs.85%29.aspx

    For more info on the Wow6432Node entries check out: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724072%28v=vs.85%29.aspx

    希望这样可以节省别人一些时间和头痛。

    Hope this saves someone else some time and headaches.

    这篇关于没有注册类从PHP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆