Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think this is going to be tricky because of two things (that I guess you have probably already discovered):</p> <ol> <li>You cannot regasm an unsigned library so that it can be exposed to COM.</li> <li>You cannot reference an unsigned library from a signed one.</li> </ol> <p>Maybe someone has a better idea but given those two constraints I think the only thing you can do is something nasty with reflection...</p> <p>Say you have a class in an unsigned library that you want to expose to COM that looks like this:</p> <pre><code>public class TestClass { public string SaySomething() { return "Hello"; } } </code></pre> <p>You can reference a signed assembly from an unsigned one so the first step could be to create an interface for just the bits of your classes you wish to expose to COM and put those interfaces in a new assembly that <strong>is signed</strong>. In our case say we define the interface thus (you can fiddle with the various COM attributes to make it to your liking):</p> <pre><code>[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface ITestClass { string SaySomething(); } </code></pre> <p>Now reference that new assembly from your original one and change the class definition so that it implements the interface.</p> <pre><code>public class TestClass : ITestClass </code></pre> <p>Now, go back to your signed assembly and add a little helper factory that looks like this (it is optional to do this but I think doing this in one place is a good idea):</p> <pre><code>internal static class ClassFactory { // Depending on how you aer hosting this you can use a relative // path here (maybe) - this gets a bit tricky to sort out and is // most likely what will cause problems private static readonly Assembly UnsignedAssembly = Assembly.LoadFrom(@"C:\...\COMClassLibrary.dll"); internal static T CreateClass&lt;T&gt;(string typeName) { return (T)Activator.CreateInstance(UnsignedAssembly.GetType(typeName)); } } </code></pre> <p>The last step would be to create a wrapped up version of your class that you can expose to COM like so:</p> <pre><code>[ClassInterface(ClassInterfaceType.None)] [ProgId("MyClasses.TestClass")] public class TestClassWrapped : ITestClass { private readonly ITestClass _original; public TestClassWrapped() { _original = ClassFactory.CreateClass&lt;ITestClass&gt;( "COMClassLibrary.TestClass"); } public string SaySomething() { return _original.SaySomething(); } } </code></pre> <p>Now register your signed assembly for COM using regasm and that should do it. Massively tedious but given your constraints it is the only thing I can think of.</p> <p>Suggested reading:</p> <ul> <li><a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.classinterfaceattribute.aspx" rel="nofollow">Class Interface Attribute</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.interfacetypeattribute.aspx" rel="nofollow">Interface Type Attribute</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/tzat5yw6%28v=vs.71%29.aspx" rel="nofollow">RegAsm Command Line</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload