質問

I'm developing a .Net component that will live inside Windows application as a plugin. This plugin will be registered on the client machine using regasm. My component embeds most of its dependencies and returns assemblies to the AppDomain when they're requested. If I try to run regasm on my single dll, it fails because it can't locate the dependencies within the folder. This will be a problem when installing the component on the client machines.

Is there a way to tell regasm where to get the embedded dlls?

What I've tried so far:

  1. Register the component with the dlls nearby then copy the single dll to the runtime folder. My component works and the dlls are discovered at runtime, but this is not an option for deployment.

  2. Hook in using ComRegisterFunctionAttribute. This only gets called if the dlls are nearby so it's not any better than #1.

I don't have any control over the fact that regasm will get called. I don't have to make my component a single dll, but it would make deployment considerably easier provided I can solve this problem.

役に立ちましたか?

解決

New Answer:

I am guessing that your [ComRegisterFunction] is over a method in a class that references types from one of the other assemblies. Your code is probably not run because it can't JIT-compile the ComRegister method because it can't find the assembly for one of the types in your class or method.

Try creating a class that has no external dependencies (other than the .net framework), and putting the ComRegisterFunction attribute in that class. Do your install work there, but only dynamically load assemblies from other types so you can use custom code to locate the external assemblies.

他のヒント

Ld00d, I had the same problem. How did you do this: "I removed the references in the COM registered dll"? It sounds like magic to me. Did you use ildasm and then ilasm?

I think there is no solution for this serious problem of regasm.exe.

regasm.exe invokes [ComRegisterFunction] method only if the previuos verification of assembly GetReferencedAssemblies ends with success. You may try to ildasm and then ilasm your dll to remove these references, but I think it could bring chaos. I also do not know what would happen if you ofuscate the code.

My workaround:

  1. During installation copy those DLLs asked by regasm.exe into the folder of your DLL.

  2. Remove them just after regasm.exe finishes registeration of your DLL.

Not nice (the installer software eats a lot of disk space), but works.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top