none
Mixed mode assembly and COM server in .NET 4.0 problems. RRS feed

  • Question

  • Hello,

    In my code, I create a COM server by using Activator.CreateInstance(SomeType).  This COM server uses mixed mode SQLite dll compiled against .NET 2.0.  I have a config file for this COMServer.exe as follows:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
    <supportedRuntime version="v2.0.50727"/>
      </startup>
    </configuration>

    The COMServer.exe will have all of its assemblies loaded under .NET 4.0 for some Windows 7 computers and this will work.  For other Windows 7 computers, it loaded mixed mode assemblies under .NET 4.0 and managed assemblies under .NET 2.0.  This causes the COM server not working.  Anyone has any idea why?  Why the app.exe.config file works for some computers and not other computers for the same set of code?

    Thank you.
    Hoang
    Wednesday, February 6, 2013 5:12 PM

All replies

  • I want to follow up with some info. How come we don't have this problem when running this application under Windows 2008 Server?   On this server, we have both the .NET 3.5 and .NET 4.0 installed.  We don't even need the app.exe.config file.  Why is that Microsoft tells us we need to do this for mixed mode assembly to work under .NET 4.0 but it isn't so on Windows 2008 Server machine? 
    Wednesday, February 6, 2013 11:35 PM
  • Hi Hdang,

    Welcome to the MSDN Forum.

    I am trying to involve some other one into this case, wait it patiently, please.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 7, 2013 11:24 AM
    Moderator
  • Hi Hdang92,
    Welcomes you to msdn forums.

    I have the same experience in my previous project. I hope you have the setup project for your application, if I am right, then try to add .net 2.0 proj config file to your setup proj and rebuild your setup project and try to install the new setup and check it now. I solved my problems now.

    By

    A Pathfinder..

    JOSwa


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful"

    Thursday, February 7, 2013 12:31 PM
  • Hello JoSwa,

    I am not sure I understand what you said.  The COMServer.exe is a Delphi exe that acts as a COM server.  It uses .NET assemblies that has been exposed as COM and it also uses SQlite 1.0.56.0 dll. This SQlite dll is a mixed mode assembly.

    I created this COM server from my managed code.  I have the COMServer.exe.config to let the COM server run in legacy mode for .NET 4.0

    Thursday, February 7, 2013 3:43 PM
  • I can positively report the following cases:

    1. On Windows 2008 R2 server, this COMServer.exe activates CLR v2.0 without the COMServer.exe.config file at all.  It just works.

    2. On my Windows 7 machine, this COMServer.exe activates CLR v2.0 for some assemblies and activates CLR v4.0 for some assemblies even the COMServer.exe.config file has this tag: <startup useLegacyV2RuntimeActivationPolicy="true">.  COMServer.exe doesn't work here because of mixed match of CLR and mixed mode assembly.

    3. On other Windows 7 machine, this COMServer.exe only activates CLR v4.0 with COMServer.exe.config file.  It works here.

    So what we have here are three different cases and it isn't consistent with what Microsoft is saying.  I would like to know why case #2 happens.  Why doesn't the config file work as in case #3.  Case #1 is a big mystery that Microsoft needs to tell us. 


    • Edited by hdang92 Thursday, February 7, 2013 5:15 PM
    Thursday, February 7, 2013 4:39 PM
  • Additional info:

    This COMServer.exe is compiled against .NET framework 3.5.  According to Microsoft document, we don't even need the config file to run on computer that has .NET framework 4.0 installed.  Here is what it says:

    "Scenario 1: Native application that uses COM components built with earlier versions of the .NET Framework.

    .NET Framework versions installed: The .NET Framework 4 and all other versions of the .NET Framework used by the COM components.

    What to do: In this scenario, do nothing. The COM components will run with the version of the .NET Framework they were registered with."

    However, it doesn't work and the famous "Mixed mode assembly is built against version ‘v2.0.50727′ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information." showed up.  We then added the config file and it works on some Windows 7 computers and not on others.

    Thursday, February 7, 2013 10:07 PM
  • The case 2 sound like the COMServer.exe entry point is .NET (mixed or not) and it uses some native code that itself dépends on .NET assemblies. The first dependancy isn't a problem and is addressed by COMServer.exe.config file. The second may be one: pure native code have to create a .NET AppDomain to launch .NET code and the problem probably come from the way the COMServer.exe native code choose the .NET CLR version for this AppDomain.
    Wednesday, February 13, 2013 11:06 PM