.NET Framework (v 4.0) COM Registration free called from Win32 C++ application

1

I need to create a registration free COM object in .Net Framework c#. I've followed the msdn walkthrough https://msdn.microsoft.com/en-us/library/ms973915.aspx. I've to work on it because, or it is not enough clear to me, or it is not correct, however this is an old post and I use Visual Studio 2015 on Windows 10, so maybe something is changed. Here in the following the steps that I've made to make it work

  1. Compile COM C# dll SideBySide.dll (Target Framework 2.0) of course I've not registered it by regasm

  2. I don't use the approach described in the tutorial it seems not work for me. I Create SideBySide.Manifest by mt.exe here the command

    mt -outputresource:"" -manifest ""

  3. I've manually modified the generated manifest to remove all unuseful tags and add the mandatory ones here in the following the modified manifest

      <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <assemblyIdentity
        name="SideBySide"
        version="1.0.0.0"
        type="win32" />
        <clrClass
                  clsid="{4B72FC46-C543-4101-80DB-7777848D1357}"
                  progid="SideBySide.SideBySideClass"
                  threadingModel="Both"
                  name="SideBySide.SideBySideClass"
                  runtimeVersion="v2.0.50727">
        </clrClass>
        <file name="SideBySide.dll">
     </file>
    

  4. I've added manifest to SideBySide.dll with command

mt -outputresource:"" -manifest "SideBySide.manifest"

  1. I've exported the tlb from SideBySide .Net dll using tlbexp

  2. I've set No in the configuration Properties -> Manifest tool -> Embed Manifest of the c++ client

  3. I've compiled client.exe and then i've applied changes to che client.exe.manifest file. Here in the following the modified manifest

    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity type = "win32" name = "client" version = "1.0.0.0" /> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="SideBySide" version="1.0.0.0" /> </dependentAssembly> </dependency> </assembly>

Everything it's work well and it seems that I can consume .Net Framework COM interface from native c++ application. However there is an issue then i try to compile the SideBySide with .Net Framework 4.0 or newer when i call CreateInstance

ISideBySideClassPtr ptr;
HRESULT hr = ptr.CreateInstance(__uuidof(SideBySideClass));

This error occurs: 0x8013101b : This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. Of course I've tried to perform all the steps listed above, I try also to specify the runtime version in the manifest of the dll but it was unuseful. I also read this post https://blogs.msdn.microsoft.com/dsnotes/2012/08/10/error-0x8013101b-when-doing-a-registration-free-com-activation/ The problem it's the same but the solution, in my opinion is not suitable for me, because I need to call c# COM from a native client.

There is some workaround to apply or i need another approach to my problem

c#
c++
com
registration-free-com

2 Answers

1

I appreciate this a little late, but for anyone else that comes across this...

I had this problem earlier today. My Registration Free COM library is built with .Net 4.5.2, my solution was to use the "runtimeVersion" attribute as follows

<clrClass 
   clsid="{...}" 
   progid="Library.Name" 
   threadingModel="Both" 
   name="Library.Name.Class"
   runtimeVersion="v4.0.30319">

Alternatively, you can leave out the runtimeVersion attribute (or specify v2.0.50272) and compile your library for .Net 3.5. Either solution appears to resolve the issue.

answered on Stack Overflow Nov 4, 2017 by 0909EM
0

I am only guessing, but you say that the runtime version is 2.0.50727 in your manifest file, but you are having trouble compiling with 4? You have a mismatch in version with your manifest and your tools.

I just use the manifest tool to create and store the information in my assembly (in PostBuild step):

"$(PathToYourTools)\mt.exe" -managedassemblyname:$(TargetPath) -nodependency -outputresource:$(TargetPath);#2

It has the added benefit of not requiring to generate the typelib for the .NET assembly.

answered on Stack Overflow Oct 11, 2016 by Joseph Willcoxson

User contributions licensed under CC BY-SA 3.0