dnSpy starts the application without attaching a debugger
murolem opened this issue · 13 comments
dnSpyEx version
6.5.0
Describe the Bug
I'm trying to debug a .NET 7.0 dll that the game loads, but dnSpy seems to not do anything. It attaches just for a mere moment, then stops doing anything, launching the application.
The game in question is Cosmoteer.
I have these settings (I didn't find the option to switch languages):
From I've read from the docs, for debugging unity games you need patched dlls, but there's no mention of non-unity games? How to debug those? I didn't find any info searching either, like there's something obvious that I'm missing.
If the game does indeed need some dll patched (I guess for invoking dnSpy methods or something?), I happen to have a C++ injector ready (that I use for modding the game by injecting C# dlls).
How To Reproduce
- Open
cosmoteer.dll
inside bin dir of Cosmoteer game with dnSpy. - Set a break point, try to launch the debugger with settings that I provided above.
Expected Behavior
- Debugger works.
Actual Behavior
- Debugger doesn't do anything except launch the game.
Additional Context
No response
Hi, could you perhaps provide me with the DLL and any .json
files located next to it via email (I assume the game is paid software, and redistributing the component publicly would not be the wisest idea)?
Thanks in advance!
From I've read from the docs, for debugging unity games you need patched dlls, but there's no mention of non-unity games? How to debug those? I didn't find any info searching either, like there's something obvious that I'm missing.
If the game does indeed need some dll patched (I guess for invoking dnSpy methods or something?), I happen to have a C++ injector ready (that I use for modding the game by injecting C# dlls).
The information about Unity games does not apply to non-Unity games. No patching should be necessary to get your .NET 7 application/game working under the debugger. If you can provide the file alongside the .json files next to it, I will be able to investigate the cause of the error further!
@ElektroKill hi!
I've sent you the DLL file and the .json
file. Look for subject dnSpy/issues/297
Hi, I took a look at the files you provided. Looking at the contents of .runtimeconfig.json
file it's evident that the file comes with an included copy of the .NET runtime. This means the game was published in self-contained mode and does not contain the necessary runtime components for debugging. There are two ways to tackle this problem:
- Install the exact .NET runtime the game requires on your computer. In this case, this would be .NET 7.0.14. After the installation, try to debug the file again with dnSpy. The latest dnSpy versions can detect the lack of these debug components and load them in from runtimes installed on the system rather than only relying on the files included in the runtime the file is using. This should allow you to debug the game as usual.
- It is also possible to convert the self-contained application into a normal application that uses the .NET installed on the system rather than the installation it ships with. This requires modifying the
.runtimeconfig.json
and.deps.json
files. AFter applying th necessary changes dnSpy should be able to debug the file without issues. Instructions on how to convert a published file into a normal file can be found here (begin from step 7 as in this case the game does not use a single file bundle and thus does not need to be unpacked): #48 (comment)
The first method is preferable as it does not require modification of the game files and I suggest you try that first. If it doesn't work, try the second method.
Let me know of the results and if the issue can be marked as closed!
@ElektroKill First one didn't work, sadly. Installed this version of .net, tried running in both .net and .net framework modes. Same result.
Second one didn't work either. Got the same error when trying to run with host:
But without it got this:
Idk why it's complaining. Clicking OK opened the download for 7.0.16 version, which I've also installed. Same error.
Then I tried installing 7.0.14 .net binaries (previously only installed the SDK) - same error.
Installed the Windows Desktop Runtime - same error.
P.S. I haven’t seen anyone respond so quickly, but at the same time so thoroughly - cheers.
Can you make sure that you installed the x64 version of the 7.0.14 runtime? You can do this by running the dotnet --info
command in the terminal and posting the output here!
If you could post the contents of C:\Program Files\dotnet\shared\Microsoft.NETCore.App
and C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App
it would also be helpful.
Microsoft.NETCore.App
dirs are too large, uploaded them to GDrive:
Huh, it looks like you do have the appropriate runtimes installed. Can you check please if inside the directory where cosmoteer.dll
resides the following files are present:
mscordaccore.dll
mscordbi.dll
I managed to obtain a copy of the game and for me those files are present and I am able to attach using dnSpy.exe when using the 64 bit version.
Okay, that's very strange. I'm not sure what could be going on here. Can you please inform me of the version of the dnSpy build you are using? (.NET vs .Net Framework and the architecture?). Information is found in the title bar. I'm using the .NET Framework 64bit version and I can debug the build of the game I obtained successfully.
Same build, but I was using .net version. Downloaded framework version, same result sadly.
I've even reinstalled the whole game - it attached for a little bit longer, but still, only momentarily 😭
That is very strange. At this point, I honestly have no idea what could be causing dnSpy to attach. All the necessary files for debugging appear to be present but for some reason when dnSpy awaits the .NET debugger startup event it times out after the 5 seconds.
Can you try one more thing and that is let the game fully load and then try to attach dnSpy through the Attach to Process
option under the Debug
menu? Let me know of the results.