0

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, but there are exceptions when you call this dll from Visual Studio 2015 application.
I can't find out how to solve this problem.

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 SharpSVN and C# 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())
      {

         try
         {
             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;
         }
      }
 }
Pavel
  • 41
  • 1
  • 6
  • This exception is generated by the just-in-time compiler when it cannot find the DLL that is needed to compile and run this code. Before your code can enter the try{} block, sayonara at the gcnew statement. You'll need to try sooner. – Hans Passant May 11 '19 at 12:59
  • Not, actually - the exception is thrown after I try to call "tmp->MyCheckOut" (and I can't get inside it), gcnew is working properly here. I tried adding gcnew inside the try block - the result is the same. – Pavel May 11 '19 at 16:51

0 Answers0