2

I use unmanaged dll with P/Invoke in this app, and I always tested it inside Visual Studio (with debug mode on x86 CPU because the dlls are only x86), and it works just fine. But when I just start the exe manually after some time (probably at the first operation with those dlls, but I don't know exactly) it says the exe has stopped working, and it starts checking for solution (I use Visual Studio 2013 on Windows 8.1, if that matters). I tried to add the dlls to the project as existing item, but that doesn't help. Also I know, that it's not because it can't find those dlls, cause if I delete them, it doesn't crash, just freeze without any error message. Shouldn't it work the same from Visual Studio as manually started?

There is also a weird bug when I run from Visual Studio: everything's work fine, but sometimes Visual Studio just suddenly stops debugging, as if the program were closed and the GUI of my app freezes, and I can only close it by closing Visual Studio (as I close it, the GUI disappears). Maybe it's a totally different problem, but it can be connected.

Edit:

Here's the project on github, if somebody could check it: https://github.com/geiszla/CycriptGUI

Some news: If I run it with Ctrl+F5 it also crashes. What's the difference between F5 and Ctrl+F5, that can cause this problem?

András Geiszl
  • 966
  • 2
  • 16
  • 36
  • do you need to register the DLL using regsvr32? have you also tried running the app in administrator mode outside of VS? – Ahmed ilyas May 08 '15 at 17:07
  • 2
    Add some logging to your application. Even a single try-catch around your main to output to the console the exception/stacktrace could probably help you a lot debug your stuff. – Pierre-Luc Pineault May 08 '15 at 17:07
  • @Ahmedilyas It's a C library, not a COM library, so as I understand I don't need to register it. – András Geiszl May 08 '15 at 17:21
  • @Pierre-LucPineault I tried to put the updateTask into try-catch, but it didn't help (I think that part is the problem, cause I use the dlls there first, and if I remove the update task starting part it doesn't crash). (See code above) – András Geiszl May 08 '15 at 17:27
  • I had a problem like this, and the reason it wasn't crashing when run under the debugger is that the offending code was within this `if` statement: `if (System.Diagnostics.Debugger.IsAttached == false)`. It's a long shot, but you might want to check whether you're deliberately running different code when attached to the debugger. – adv12 May 08 '15 at 17:48
  • I deleted my answer ,useful link: [libimobiledevice-dotnet](https://github.com/chefvonaustralien/libimobiledevice-dotnet) – houssam May 08 '15 at 18:57
  • Possible solution here: http://stackoverflow.com/q/16696444/395718 – Dialecticus May 08 '15 at 19:54
  • Please don't ask the question in an offsite link. – David Heffernan May 08 '15 at 20:50

2 Answers2

1

Thanks for every help, my problem was solved: I called an unmanaged function with only 2 parameters, while it had 3. However I still don't understand why it worked with debugging mode, and not without debugging.

András Geiszl
  • 966
  • 2
  • 16
  • 36
  • 1
    undefined behaviour is a b**tch, be happy that it failed immediatly, not 6 months from now in production at midnight for your biggest customer – pm100 Feb 10 '17 at 00:54
1

Searched all over Google with no real simple answers. Here it is folks(at least it worked for me and is simple):

When you run the console app in Visual Studio, look at the output window at the bottom, get the location of the ..\bin\Debug\*.exe

Copy the *.exe and the *.config to your desired folder, run it, it should work the same way in Visual Studio.

sojim2
  • 1,245
  • 2
  • 15
  • 38