CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to set runtime version when calling C++ DLL from C++ app (Visual Studio 2015)?

Hybrid View

  1. #1
    Join Date
    May 2019

    How to set runtime version when calling C++ DLL from C++ app (Visual Studio 2015)?

    I need to call C# functions (SharpSVN API) from C++ 64-bit application (without Common Language Runtime Support).

    C# functions are in the Subversion DLL - SharpSvn.dll. I use rather long scheme: C++ app (unmanaged code) is loading my C++ library (with managed code) which is calling my C# library which is calling SharpSvn.dll
    The problem is that SharpSvn.dll is using 2.0 runtime (v2.0.50727) and this parameter should be set in the App.config. But my C++ DLL (with Common Language Runtime Support) ignores this parameter - I receive FileLoadException while debugging.
    If using Visual Studio 2008 for C++ dll and for c# dll - it works OK, if I call C# dll from the С# application with Visual Studio 2015 - it works OK, too.
    I can't find out how to solve this problem in Visual Studio 2015.

    Resources that I used:
    1) https://sharpsvn.open.collab.net/docs/walkthrough.htm - "If you are like me and running this project in Visual Studio 2010 with the .NET 4.0 framework, you likely just encountered a nasty FileLoadException saying something like "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."
    2) SharpSVN and C# Problem https://stackoverflow.com/questions/...-sharp-problem

    C++ app (no CLR)

    std::wstring msg_loc;
    s_svn->CheckOut(db_path, working_d_path, user_name, user_passwd, file_path, msg_loc);
    if (!msg_loc.empty()) MessageBox(msg_loc.c_str());
    C++ dll (with managed code)

    SS_state SVN_extern::CheckOut(const std::wstring &db_uri, const std::wstring &wd_path,const std::wstring &user_name, const std::wstring &u_passwd,const std::wstring &Path1,std::wstring &Mess,bool ignore_db_diff)
     M_SVN_Class ^tmp = gcnew M_SVN_Class();
     Mess = L"c# class created.";
     String ^msg = L"";
     SS_state res;
     try {
          if (tmp->MyCheckOut(db_path, working_d_path, u_name ,user_passwd, file_path, msg, ignore_db_diff)) res = SUCCESS;
          else res = FAILURE;
          Mess = marshal_as<wstring>(msg);
         catch (...) {
          res = FAILURE;
          Mess = L"Checkout exception";
         return res;
    C# dll

    public bool MyCheckOut(string db_uri, string wd_path, string user_name, string u_passwd, string file_path, ref string Mess, bool ignore_db_diff)
          using (SvnClient client = new SvnClient())
                 client.Authentication.ForceCredentials(user_name, u_passwd);
                 SvnUpdateResult result;
                 SvnCheckOutArgs args = new SvnCheckOutArgs();
                 client.Lock(file_path, "");
                 return true;
             catch (SvnException se)
                  Mess = se.Message;
                  return false;
             catch (UriFormatException ufe)
                  Mess = ufe.Message;
                  return false;

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004

    Re: How to set runtime version when calling C++ DLL from C++ app (Visual Studio 2015)

    A few questions:
    1) Is the sharpsvn.dll 64-bit?
    2) Is the managed dll .net 2.0 and 64-bit?
    3) Is the sharpsvn.dll COM enabled?

    Both the sharpsvn and managed dlls need to be compiled for 64-bit to be called from your 64-bit program.

    As an alternative, if the sharpsvn.dll is COM enabled (and 64-bit), you have the option of registering it and directly calling it as a COM object in within your 64-bit c++ app (unless the managed dll provides some additional functionality). This may simplify the code.
    Last edited by Arjay; May 15th, 2019 at 03:26 PM.

  3. #3
    Join Date
    May 2019

    Re: How to set runtime version when calling C++ DLL from C++ app (Visual Studio 2015)

    1) There are 32-bit and 64-bit versions of sharpsvn.dll, I use 64-bit.
    2) The managed dll is 64-bit but it is not .net 2.0. As far as I understand there are different CLR versions, for example 2.0 (.Net 2.0 3.0 3.5) and 4 (.Net 4.0 4.5 etc). I supposed .Net 3.5 is enough - my VStudio 2008 solution is .Net 3.5 and is working with sharpsvn.dll properly.
    3) Currently I don't know if sharpsvn.dll is COM enabled, haven't find such description. I've asked the developers about that.

    As I see, if I add the parameter <startup useLegacyV2RuntimeActivationPolicy="true"/> to the App.config (in <configuration>) of the application using my C# dll - it starts working properly. The thing is that it works for c# app but I don't know how to set this parameter to the managed dll.

    Currently I use managed dll built under VStudio 2008 with LoadLibrary - but using two versions seems to be rather strange.
    Last edited by Quarter; May 16th, 2019 at 02:37 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)