Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLR event handlers #98

Open
daddycocoaman opened this issue Feb 2, 2023 · 1 comment
Open

CLR event handlers #98

daddycocoaman opened this issue Feb 2, 2023 · 1 comment

Comments

@daddycocoaman
Copy link

Hi,

Thank you so much for creating a great library. Do you have an example of how to use the add_* and remove_* functions here?

add_AssemblyLoad*: proc(self: ptr AppDomain, value: POBJECT): HRESULT {.stdcall.}

My scenario is that I'm trying to load a bunch of DLLs and the DLLs that have dependencies on other DLLs fail to return types when calling GetTypes(). My assumption is that the DLLs have to be loaded or resolved in a certain order so that there's no dependency failure. In pythonnet, I can do something like this:

def assembly_resolve(app_domain, resolve_event_args):
    name = resolve_event_args.Name.split(",")[0]
    try:
        return next(x for x in app_domain.GetAssemblies() if x.GetName().Name == name)
    except StopIteration:
        pass
        
System.AppDomain.CurrentDomain.AssemblyResolve += assembly_resolve

I'm trying to accomplish the same with winim but unsuccessful.

proc resolveAssembly(domain: CLRVariant,
    resolve_event_args: CLRVariant): CLRVariant =
  echo "RESOLVING FROM: " & $domain
  echo "RESOLVING: " & $resolve_event_args.Name

  for assembly in domain.GetAssemblies():
    if assembly.Name == resolve_event_args.Name:
      return assembly

proc setupClr(): CLRVariant =
  var appDomain = clrStart()

  # Add the assembly resolver
  appDomain.CurrentDomain.add_AssemblyResolve(cast[pointer](resolveAssembly))
  load("mscorlib") # Expect resolveAssembly to be called here
  return appDomain.CurrentDomain

Thanks for any help you can provide.

@daddycocoaman
Copy link
Author

Although I'm still interested in the answer to this, I solved my issue by merging all the DLLs and dependencies into a single DLL using ILMerge and I was able to get the types I needed. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant