-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.Net 5.0 Application using NAudio libraries crashes without any error message #54132
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Last week I installed Windows Updates and upgraded to Windows 10 21H1 after. I started a .NET 5 application that uses NAudio that worked fine the day before and after the upgrade it closed with Access Violation unhandled exception. Changing the runtime to .Net Core 3.1 fixed the issue. |
Sadly I´m not being able to downgrade to .NET Core 3.1. But referring to this comment, it is indicating, that there is a bug in the "hotfix" of the current .NET 5.x runtime, which lets the windows kernel kill the application with "Access Violation". |
It would be beneficial if anyone on Windows 20H2 could test this in .NET 5+, that way it would determine if a windows update was involved in the regression. |
I´m currently running 20H2 and couldn´t run it with all .NET 5.x versions. I´ve edited the original message to state this :) |
I tried on another computer with .NET 5.0.6 and Windows 10 20H2 and it works.
So to me this is clearly a 5.0.7 issue not present in 5.0.6 |
@jkoritzinsky Can this be regression introduced by #50882 ? |
It works if you published self-contained |
I created a repro project at https://github.com/jackpoz/NetCore507Crash |
https://github.com/jackpoz/NetCore507Crash fails for me with:
|
To me it really looks like a memory pointer issue. It also is NOT the latest cumulative update. It's one of the .NET security updates. I've uninstalled the 2 latest cumulative updates and it didn't fix it. :/ |
@jkotas I added now a check in case the buffer gets full, I never reached that point in my tests with 5.0.7 as it crashes right away. Please pull latest version. |
I don't think this is caused by #50882 since that aligned all of the behavior to match .NET Core 3.1, but I guess it's possible that NAudio hits some corner case in it's interop. Without knowing if it even uses LayoutClass marshalling though, I don't know. |
It does use The affected code is here: https://github.com/naudio/NAudio/blob/fb35ce8367f30b8bc5ea84e7d2529e172cf4c381/NAudio.WinMM/WaveOutBuffer.cs#L140 . This code depends on WaveHeader to be marshaled using pinning strategy. Here is small test to demonstrate the problem: On 5.0.6 (and .NET Framework), the program below prints pointers that are really far apart (GCHeap and stack):
@jkoritzinsky Could you please take it from here? @jackpoz Thank you for providing good repro! |
I'm trying to figure out how this depends on the pinning optimization. I specifically added a compat feature as part of the change in 5.0.7 to automatically marshal both to and from native whenever a layoutclass with blittable contents is passed to ensure compat as well as tests to validate the behavior, so any dependency would have to be on the address itself and not the implicit side effects. |
The |
So it does actually depend on the address. 😢 I'll put together a fix for this and once it's in we can decide if we want to backport it. |
Whats interesting though is that it works on .NET 6 preview 3. So either the pinning optimization has been changed in preview 3 or something else is going on. |
I am wondering it its a combination windows updates and .NET 5. Unless I am switching runtimes incorrectly (which is very possible) it doesn't work on any version of .NET 5 on my computer. |
Same here. 5.0 completely broken |
This is the same for me. Confusing, that this is not happening to all, as a few on here and on the NAudio Issue were able to run it with another .NET version. |
So I tested on another machine that only had 5.0.1 installed. It ran just fine. Tried same thing/version on the original machine same problem with crashing. Then, I uninstalled the June 2008 security update for 5.0.7 and now it works on my original machine. So it is the issue with 5.0.7 as mentioned above, what is still weird to me is why having 5.0.7 installed breaks all versions of .NET 5 even if you run with an older version. |
Applications targeting 5.0.x will automatically roll forward to the latest 5.0.x installed by default. |
…backcompat. Fixes dotnet#54132 Fixes dotnet#53542
I created a |
The same fix that went into .NET 5 that broke this also went into .NET 6 in the Preview 4 time frame, so a fix is needed for .NET 6 as well. |
fun fact: it works fine on 5.0.8 and 6 preview 4 and later for me |
Perhaps some other code in .NET 6 Preview 4 that made it work was forgotten in the backport and it just works in .NET 6 Preview 4 because of coincidence. |
The crash is caused by use-after-free bug. The crash will only happen if something else actually modified the freed memory in a specific window of time. It is certainly possible that the crash will come and go due to unrelated changes - that's the nature of use-after-free bugs. |
Would anyone here be willing/able to test that their NAudio scenario is fixed if I share a .NET runtime build with the proposed fix? |
I am willing test my NAudio WPF app. |
I am also ready to try with my WPF app. |
I would test it with input and instant output on console applications. |
Maybe worth noting, that I'm running NAudio 2.0.0 on 5.0.6 as I have not 5.0.7 installed and having a very similar, but slightly different problem: Microsoft's Maybe Helpful DetailsIn WPF I use NAudio to only change volume on default audio device and play a test-sound with QuestionWould this still be explicable with the found bug, or is this then maybe another issue? Event viewer (multiple entries like this)
|
It is very unlikely to be related to this bug. I would recommend reporting it via Windows Feedback. It looks like a Windows OS bug to me. |
This may also not be related but I mention it anyway. I have stopped using NAudio to play wav files but still use the Volume get and set in NAudio and GetDefaultRenderDevice().AudioMeterInformation.MasterPeakValue. This has not happened prior to net v5.07 |
For everyone who wants to validate this, I've added a link to a zip at the end of this comment with an x64 runtime. If you set the |
Thanks. Worked with my NAudio WPF app. Any word on how long before this fix will make it into an official public release? Days, weeks or months? |
Reopening to track the servicing fix. |
This will likely be more on the scale of months rather than weeks due to the servicing timeline. |
OK. That's disappointing,, I understand. |
The sad thing here is that NAudio is widely used. It has 2.34 Million downloads on github and there is currently nothing that comes close to it's functionality that is maintained. |
That option would have to be considered by the owners of NAudio, and based off the parallel issue over there, it seems it might be. |
A new version of NAudio is available (2.0.1) that resolves this issue by making |
Fixed by #54244 |
Description
Hey Guys,
It seems something on .NET 5 made NAudio (master-branch) crashing without any error message.
There is also an open Issue open on the NAudio´s GitHub.
After discussions i found out, that the runtime tries to access memory it does not own so Windows kills the process with Access Violation.
Configuration
It happens on Windows 20H2 with ANY .NET 5.X.X version.
Related information
Based on the issue from NAudio, it was referred, that .NET Core 3.1 is working. I only could verify it for .NET 5.
The text was updated successfully, but these errors were encountered: