Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8904673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:11:36+00:00 2026-06-15T02:11:36+00:00

This is a kind of complex question, hitting on somewhat arcane areas relating to

  • 0

This is a kind of complex question, hitting on somewhat arcane areas relating to COM, the CLR, and reg-free COM.

First, my main application is written in python. As such, it’s codebase (in development) is at, say, C:\mainapp\main.py.

Of course, on windows, it is C:\Python27\python.exe that executes the program.

I now want to use reg-free COM from python (using win32com) to talk (using IDispatch) to a COM object written in C# that I control, that is located at C:\mainapp\ManagedCOMObject.dll


Note: If you don’t speak python / pythoncom, note that the call to Dispatch() eventually boils down to CoCreateInstance().


Attempt 1

#main.py:

import win32com.client
CLSID_ManagedComObject_MyClass = "{zzzzz....}" #This is correct
myclass = win32com.client.Dispatch(CLSID_ManagedComObject_MyClass)

Result

Failure, because the object is not in the registry (as expected), and I didn’t mention anything about manifest files, and python.exe’s manifest obviously doesn’t know about my object.


Attempt 2

#main.py:

ac = ActivationContext("C:\mainapp\myapp.manifest", asm_dir="C:\mainapp")
with ac.activate():
    #The above two lines fill in a ACTCTX structure, call CreateActCtx, and call ActivateActCtx 
    import win32com.client
    CLSID_ManagedComObject_MyClass = "{zzzzz....}" #This is correct
    myclass = win32com.client.Dispatch(CLSID_ManagedComObject_MyClass)

–

#myapp.manifest:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity type="win32" 
                name="My.Main.App" 
                version="1.0.0.0" 
                processorArchitecture="x86" 
    />
    <dependency>
        <dependentAssembly>
            <assemblyIdentity
                        name="ManagedComObject" 
                        version="1.0.0.0" 
                        processorArchitecture="msil" 
            />
        </dependentAssembly>
    </dependency>
</assembly>

Note that ManagedCOMObject has an embedded manifest, which declares the COM object using the clrClass tag.

Result

The ActicateActCtx call succeeds and correctly parses the manifests of myapp.manifest and ManagedComObject.dll – I verified this using sxstrace.exe.

The call to CoCreateInstance fails with FileNotFound, after probing for C:\Python27\ManagedComObject.dll. The fusion log claims that PrivatePath is not set (presumable because python.exe.config doesn’t exist), and simply does not look for the C# object in C:\mainapp.

Questions

  1. Why is this failing? I believe it is because the CLR COM loader stub is unable to import my C# assembly. If it failed before this step, the CLR would not even load, so the very fact that it is probing and creating fusion logs leads me to belive it is because the CLR can’t find ManagedCOMObject.dll.

  2. Note that the CLR is loaded – I believe this means that COM has successfully looked at the current activation context to find the registration. I don’t know precisely what clrClass does in the manifest, but presumably it got the CLR loaded successfully.

  3. I assume now that the issue is the CLR is not paying attention to the ActCtx when loading assemblies. If I was writing managed code, I could hook into the AppDomain.CurrentDomain.AssemblyResolve event and find the DLL myself. Since instead i’m writing unmanaged code, and hosting the CLR only implicitly, can I somehow change my applications PrivatePath and/or how assemblies are probed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:11:37+00:00Added an answer on June 15, 2026 at 2:11 am

    I assume now that the issue is the CLR is not paying attention to the ActCtx when loading assemblies

    Yes, that’s correct. The CLR has its own strategy to locate assemblies that isn’t otherwise affected by the Windows activation context. By default it only looks in the GAC and then in the private bin path of the EXE. You can see this at work with the Fuslogvw.exe utility.

    You don’t have many great options here. Installing the assembly in the GAC is the obvious solution and in general appropriate for [ComVisible] assemblies since it helps solve the COM DLL Hell problem. Only other thing you can do is copy it to C:\Python27 directory or write a python.exe.config file in that same directory that changes the probing path to a subdirectory of C:\Python27. Neither scales well. Hosting the CLR yourself or writing an AppDomain.AssemblyResolve event handler are off the table.

    Using the GAC is the appropriate solution if you want to avoid Regasm.exe /codebase

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This was the first time I encountered this kind of error after dealing with
My pages contain this kind of url: http://fashion.piliapp.com/author/http%3A%2F%2Fwww.wretch.cc%2Fblog%2Fwiwinnie/ which created by http://fashion.piliapp.com/author/ . rawurlencode(http://www.wretch.cc/blog/wiwinnie)
I have this kind of question. In my form, i got this as a
This is kind of a follow-up question to Perl: add character to begin of
I hope this place is the best for this kind of question. I've the
This kind of code would normally work in PHP, but since the scope is
this kind of emergency, so please, can someone help me... I'm using movingboxes plugin
I perform this kind of query in my Python code to conn = rdbms.connect(instance=_INSTANCE_NAME,
How to do this kind of events when I pressed the Preferences Button I
I'm getting this kind of errors while compiling any of the Win 8 Metro

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.