Reference private assembly in thread, C#


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:


<?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="" 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="" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
  <assemblyIdentity name="theProgram.exe" version="" processorArchitecture="x86" type="win32" />
    <dependentAssembly asmv2:dependencyType="install" asmv2:codebase="theCom.dll.manifest" asmv2:size="756">
      <assemblyIdentity name="theCom.dll" version="" type="win32" />
      <hash xmlns="urn:schemas-microsoft-com:asm.v2">
          <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
        <dsig:DigestMethod Algorithm="" />

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">

    version="" />

<file name = "theCom.dll">

    threadingModel = "Apartment" />

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


    tlbid = "{2EC9A174-C7CA-4DF8-ABA0-47095DA87277}" />


Creation of the thread:

myThread = new Thread(threadClass.StartMethod);

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();
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