Unregistered Error Class from PHP

We created the assembly of the C # class library and made it COM visible in order to be able to call its methods with PHP. This worked fine, but now we wanted to install it on Windows Server 2008, and we continue to go by the error "Class not registered."

To eliminate any dependency issues, I made a small small library of test classes in C #. The class library is built for any processor, and it is visible to COM (also set COMVisible to true in AssemblyInfo.cs). The test class library contains only one class with one method. The class is called TestLib, and the namespace is also called TestLib. This method is called Test and returns a string.

We did the following: - built 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 are just trying to create a new COM instance:

try { $test = new COM("TestLib.TestLib"); } catch (Exception $e) { die($e->getMessage()); } 
  • when we call this test script from a browser or command line (php -f test.php), we get a "Class not registered" error in both cases

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

Then I tried to compile a test library with .NET 2.0 instead of 4.0 as the target structure, the same .. NET framework 4.0 is installed on the server, by the way.

Any ideas?

+4
source share
2 answers

Okay, so after some research I figured it out. The php.exe process is 32 bits. The COM-visible assembly is compiled for any CPU, so it should be available for both 32-bit and 64-bit applications.

The problem is that on a 64-bit OS php.exe and any 32-bit process searches the HKEY_CLASSES_ROOT \ Wow6432Node \ CLSID instead of HKEY_CLASSES_ROOT \ CLSID in the HKEY_LOCAL_MACHINE \ Software \ Classes \ Wow6432Node \ CLSID instead of the HKEY_LOCAL_MACHINE \ Software \ Classes \ CLSID The registry entries in the Wow6432 keys are not created by the regasm that ships with the .NET framework v4 on Windows Server 2008. They are created in Windows 7, do not ask me why.

It also turned out that if I create a small test assembly for .NET v2.0 and register it with regasm, which comes with the .NET framework v2.0, it creates Wow6432Node entries in Windows 2008. It's strange.

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

 regasm /regfile MyClassLib.dll 

This creates the MyClassLib.reg file with only β€œnormal” 64-bit entries. Then I exported the Wow6432Node keys from a Windows 7 computer and added it to this .reg file. Now, when I import this reg file into the Windows 2008 registry, everything works fine.

For more information about Wow6432Node entries, follow these steps: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724072%28v=vs.85%29.aspx

Hope this saves someone else some time and headaches.

+2
source

If you are trying to call the 32-bit COM DLL on 64-bit Windows, you need to register it.

  • Copy the 32-bit DLL to C: \ Windows \ sysWOW64
  • Run C:\Windows\sysWOW64\regsvr32.exe your_com_32.dll

A bit more information with screenshots .

0
source

Source: https://habr.com/ru/post/1416541/


All Articles