Author Topic: Failed to run exe to write to dropbox  (Read 1500 times)

0 Members and 1 Guest are viewing this topic.

drawdraw

  • Mosquito
  • Posts: 14
Failed to run exe to write to dropbox
« on: December 25, 2023, 08:38:58 PM »
I had made a c# code to write something to a text file in dropbox, using refresh token.
The c# code was compiled to exe file, named "bdcmcode_services.exe".
If I just double click the exe file, it works properly,
but if I run it in autolisp (startapp "bdcmcodes_services.exe"), it failed.
The error message was attached below, some extract is: Could not load file or assembly 'Dopbox.Api'.

Anyone know how to solve this problem ?
« Last Edit: December 25, 2023, 08:45:31 PM by drawdraw »

kozmos

  • Newt
  • Posts: 114
Re: Failed to run exe to write to dropbox
« Reply #1 on: December 25, 2023, 10:49:40 PM »
Maybe try to use Shell.Applciation to run the EXE?
KozMos Inc.

drawdraw

  • Mosquito
  • Posts: 14
Re: Failed to run exe to write to dropbox
« Reply #2 on: December 26, 2023, 12:09:47 AM »
Can give me an example code ?
I have no experience with this.

kozmos

  • Newt
  • Posts: 114
Re: Failed to run exe to write to dropbox
« Reply #3 on: December 26, 2023, 12:13:03 AM »
Code - Auto/Visual Lisp: [Select]
  1.   (vlax-create-object "Shell.Application")
  2.   "shellexecute"
  3.   (findfile "bdcmcodes_services.exe")
  4.   ""
  5.   ""
  6.   "runas"
  7.   0
  8. )
  9.  
KozMos Inc.

drawdraw

  • Mosquito
  • Posts: 14
Re: Failed to run exe to write to dropbox
« Reply #4 on: December 26, 2023, 12:44:56 AM »
Now I know the reason, I need to copy Dropbox.Api.dll and Newtonsoft.Json.dll to the support path, the dlls were created while compiling my exe . After copying, both (startapp "bdcmcodes_services.exe") and your Shell.Application method works.

Thank you very much !

Any difference for running exe by "startapp" and Shell.Application ?

Is there any way to include dll into exe, so we only have 1 file to distribute ?
« Last Edit: December 26, 2023, 12:57:54 AM by drawdraw »

kozmos

  • Newt
  • Posts: 114
Re: Failed to run exe to write to dropbox
« Reply #5 on: December 26, 2023, 06:52:08 AM »
If the DLL was created while compiling EXE, I do not think it is possible to assemble it into EXE in the same procedure. As an alternative, you can ZIP the EXE and DLL, and use lsp to exteact them and run the EXE. Thus, you can only distribute the ZIP file.
I have posted code here (http://www.theswamp.org/index.php?topic=58631.msg616674#msg616674) to extract files from ZIP.
KozMos Inc.

BIGAL

  • Swamp Rat
  • Posts: 1416
  • 40 + years of using Autocad
Re: Failed to run exe to write to dropbox
« Reply #6 on: December 26, 2023, 06:15:49 PM »
I use this to provide a complete package install, the zip is like 30mb, the path has been created in the install lisp. As its sent as an email the location of the zip is unknown.

Code: [Select]
(setq filename (getfiled "Select the File \"Cad tools 12-09-2023\"" "" "ZIP" 16))

; unzip
(startapp (strcat "powershell -command Expand-Archive -Path '" filename "' -DestinationPath 'C:/CAD-TOOLS' -FORCE"))
A man who never made a mistake never made anything

drawdraw

  • Mosquito
  • Posts: 14
Re: Failed to run exe to write to dropbox
« Reply #7 on: December 26, 2023, 08:41:02 PM »
Thank you very much to kozmos and BIGAL !

From online searching, I found a way to compile an exe which includes all the dll, by using NuGet reference Costura.Fody.
After installing Costura.Fody in Visual Studio, just compile as usual, then you will have all the dll inside the exe.

Here is a video in Youtube showing this simple process.
https://www.youtube.com/watch?v=jeghRQHjnSo&t=1s