Search code examples
.netcommanifestside-by-side

OLE Error 80131522 when trying to access a .NET assembly side by side from a native application


I have an application (Delphi Native code) that needs to access a .NET assembly (exposes a few COM classes. I want to do this using side by side assemblies and manifests. I have done this with a test .NET assembly, but am having a problem with the assembly I need to access.

When the assembly is registered, I can instantiate the COM class. As soon as I unregister the assembly, and try to access side by side I get the above error. My native application has an application manifest, which has a simple dependency to the assembly.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32"
                    name="TestApplication.exe"
                    version="1.0.0.0"/>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
        name="TestAssembly"
        version="1.0.0.0"
        processorArchitecture="x86"
        publicKeyToken="xxxxxxxxxxxxxxxx"
        type="win32"/>
    </dependentAssembly>
  </dependency>
</assembly>

My Assembly manifest, which I have embedded as a resource into my .net assembly is the following :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
    name="TestAssembly"
    version="1.0.0.0"
    processorArchitecture="x86"
    publicKeyToken="xxxxxxxxxxxxxxxx"
    type="win32"/>
  <clrClass
    clsid="{F3F1623D-DB4A-4152-9A5D-5A465AD3A318}"
    progid="TestAssembly.MyObject"
    threadingModel="Both"    
    name="TestAssembly.MyObject"
    runtimeVersion="v2.0.50727">
  </clrClass>
  <file name="TestAssembly.dll">
  </file>
</assembly>     

The manifests seems to be setup correctly. If I change the application manifest's dependency name, version or public key token (the one in the example is not the one i have in my code btw), I get the usual SxS error about the application configuration is incorrect.

I have this working on another (admittedly simpler) .NET assembly, but cannot figure out what is wrong. Problem is I'm not sure what the error means.


Solution

  • To generate .Net assembly manifest use mt.exe like this

    c:>mt.exe -nologo -managedassemblyname:"your_binary.dll" -nodependency -out:"temp_file.manifest"
    c:>mt.exe -nologo -manifest "temp_file.manifest" -outputresource:"your_binary.dll";2
    

    Then open temp_file.manifest and copy assemblyIdentity tag verbatim under dependency\dependentAssembly tag of your delphi executable manifest.

    FYI: You have to keep both the executable and all dependent .net dlls in the same folder.