none
Use .NET 2 library through COM on machine with .NET4+ only RRS feed

  • Question

  • I know that managed applications can specify supported runtimes in their config file, thus running on both 2.0 and 4.0 CLRs.
    However I have class library compiled against 2.0, which is used by VB6 application through COM.
    The problem is running the application on a machine with .NET 4.0+ version only, gets "Automation error" which is caused because the 2.0 CLR is not present.
    As I understand applications have native code which looks at the config file and loads the appropriate CLR version and libraries don't.
    Is there a way to use managed library through COM regardless of the version of the present CLR(s)?

    Tuesday, July 31, 2018 7:16 PM

All replies

  • By default, if your application expects .NETv2 but only v4 is available, it'll still try to load your application with v4, which may or may not work.

    In your case, if the automation library is plain COM interop, you can try to run "tlbimp" in your developer command prompt to regenerate the proxy class needed and see if it works for you.

    (I remember there needs to be a special compatibility control hosting the VB6 controls exposed via COM in order to properly receive events, but forgotten the control name so can't check if that exists in .NETv4)

    P.S.: I just found posts I've written in BBS before 2005 are no longer searchable in Google, maybe there're already too much information so Google cannot contain them all.
    Wednesday, August 1, 2018 2:34 AM
    Answerer
  • I'm not sure what you mean by plain COM interop.
    The .NET library has couple of classes that are marked COM visible, that are used by a VB6 application.
    RegAsm.exe is used to generate the TLB file and register the assembly in the registry.

    I've compiled the library as a console application and with the App.config file (containing supportedRuntimes) present, it's running without problems on machines with 2.0/4.0 or both CLRs.
    Running the application without the App.config file on a machine with 4.0 CLR only causes the .NET Fx 2.0/3.5 installation wizard to open.

    The exact error is "Run-time error '-2146232576 (80131700)': Automation error".

    So the question is: how to make a 2.0 managed library load the 4.0 CLR when used through COM?

    Wednesday, August 1, 2018 11:59 AM
  • > I'm not sure what you mean by plain COM interop.

    "Plain" as in "not doing anything special".

    In one of my ex-company, we were doing transition from VB6 to .NET. The route we choose is to make every form of original VB application COM visible, and host it inside wrapper WinForm in C# application.

    This kind of works, but we found that all VB form that is written to process custom Windows message stopped working. We later found that there is a compatability control that we need to use to host that form in order to process those messages.

    >RegAsm.exe is used to generate the TLB file and register the assembly in the registry.

    Note that it only works for COM visible binaries written in .NET framework, while tlbimp work for all ordinary COM binaries including those written in VB6 because it just create wrapper class for you to do the automation (you still need to run regsvr32.exe on that COM library before using it). If you found it works for you, chances are the libraries you're talking about is not VB6 binaries at all.

    In that case you have more to worry about other than "whether we can use interop libraries compiled for .NETv2 in a .NET v4 EXE".


    Thursday, August 2, 2018 1:16 AM
    Answerer