Search code examples
c#dll32bit-64bitregsvr32

Corflags.exe reports a DLL as PE32, however 32-bit regsvr32.exe won't register it


Windows 11 x64 21H2

I have a .NET 4.7.2 COM-visible DLL (not mine) in c:\program files (x86)\common\xyzshared\xyz.dll. It should be built for either 32-bit or AnyCPU. Corflags.exe reports it as PE32. However when I try to register it:

c:\windows\syswow64\regsvr32.exe "c:\program files (x86)\common files\xyz shared\xyz.dll"

... it throws up a dialog to the effect that

"The module ... may not be compatible with the version of Windows you're running ..."

It doesn't work with the 64-bit regsvr32.exe either, which these days will automatically spawn the 32-bit version as needed anyway.

I examined it with the Dependencies tool (depends.exe doesn't appear to work on Win 10+). I assume the highlighted reference to Framework64 isn't an issue.

Dependencies

It appears to be 32-bit so should register on Windows 64-bit and I'm using the 32-bit regsvr32.exe ...

Any pointers?


Solution

  • There are a couple of misconceptions in your question:

    • regsvr32 -- .NET COM assemblies are supposed to be registered with regasm instead.

    • About the whole AnyCPU thing, that's absolutely nothing to glance over like you did. AnyCPU isn't a native binary format, it's something .NET can do because it's compiled at run-time. The native part of the code is 32-bit and just starts the .NET JIT to compile the rest. That's why if you care about the binary format of your executable (like with native interop), you need to decide from the start if it's 64-bit or 32-bit. AnyCPU won't do it.