Reference private assembly in thread, C#

1

Winforms-application in C#, .net 4.5.2.

I wish to handle all communication with a private COM-assembly in a thread. However, I get

"This operation failed because the QueryInterface call on the COM component
for the interface with IID xxxx-xxx failed due to the following error: No
such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)".

If I use regsvr or the installation process to register the assembly it works as intended, but I want the assembly to be private due to previous dll hell issues.

If I handle the dll from the main thread, it works as intended, but I would like to do this in the thread.

The thread is looking in the correct directory, I can find the assembly using reflection (but that makes the rest of the coding quite difficult...).

As far as I can tell, you cannot use multithreaded apartment in winforms, and additionally, this is likely not a good idea.

So... is it possible to access a private assembly from a thread? What am I missing?

Some more info:

theProgram.exe.manifest:

<?xml version="1.0" encoding="utf-8"?>
<assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
  <assemblyIdentity name="theProgram.exe" version="5.0.0.0" processorArchitecture="x86" type="win32" />
  <dependency>
    <dependentAssembly asmv2:dependencyType="install" asmv2:codebase="theCom.dll.manifest" asmv2:size="756">
      <assemblyIdentity name="theCom.dll" version="1.0.0.0" type="win32" />
      <hash xmlns="urn:schemas-microsoft-com:asm.v2">
        <dsig:Transforms>
          <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
        </dsig:Transforms>
        <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
        <dsig:DigestValue>m2iQCXnuLAKN5aCVPExSBjLBBxzrHjXzs8s6pVAhnP8=</dsig:DigestValue>
      </hash>
    </dependentAssembly>
  </dependency>
</assembly>

The manifest for the com:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

<assemblyIdentity
    type="win32"
    name="theCom.dll"
    version="1.0.0.0" />

<file name = "theCom.dll">

<comClass
    clsid="{256DE321-02F0-4238-8116-2A40E62DDBFE}"
    threadingModel = "Apartment" />

<typelib tlbid="{2EC9A174-C7CA-4DF8-ABA0-47095DA87277}"
       version="1.0" helpdir=""/>

</file>

<comInterfaceExternalProxyStub 
    name="InterfaceThingy"
    iid="{6ECD465F-DD96-4DBE-A844-E71237881C1B}" 
    proxyStubClsid32="{00020424-0000-0000-C000-000000000046}"
    baseInterface="{00000000-0000-0000-C000-000000000046}"
    tlbid = "{2EC9A174-C7CA-4DF8-ABA0-47095DA87277}" />

</assembly>

Creation of the thread:

myThread = new Thread(threadClass.StartMethod);
myThread.Start();

Instantiation of a type from the com. Works in the main thread regardless of registration, in the subthread only if the COM is registered.

if (m_Type == null)
     m_Type = new TypeCtl();
c#
multithreading
com
private
asked on Stack Overflow Jun 22, 2020 by Camilla W • edited Jun 23, 2020 by Camilla W

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0