C
C#2y ago
CoRoys

❔ System.AccessViolationException from Windows.Media.Audio.AudioPlaybackConnection (UWP)

For familiarity, AudioPlaybackConnection on UWP enables an A2DP sink Bluetooth profile connection between Windows and another device (for receiving audio playback). Following https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/enable-remote-audio-playback, the app crashes on TryCreateFromId():
ConnectionInfo = $"Connecting to {CurrentDevice?.Name ?? "selected device"}...";

try
{
using var connection = AudioPlaybackConnection.TryCreateFromId(device.DeviceInformation.Id);

await connection.OpenAsync();

ConnectionInfo = $"▷ Connected to {CurrentDevice?.Name ?? "device"}";
}
catch (Exception x)
{
_ = await ShowDialogueAsync($"An error occurred while trying to open a connection:\n\n\n{x}", "Error");
Disconnect();
}
ConnectionInfo = $"Connecting to {CurrentDevice?.Name ?? "selected device"}...";

try
{
using var connection = AudioPlaybackConnection.TryCreateFromId(device.DeviceInformation.Id);

await connection.OpenAsync();

ConnectionInfo = $"▷ Connected to {CurrentDevice?.Name ?? "device"}";
}
catch (Exception x)
{
_ = await ShowDialogueAsync($"An error occurred while trying to open a connection:\n\n\n{x}", "Error");
Disconnect();
}
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
As seen in the screenshot attached, this exception is a ghost. Does anyone have any idea how to debug this?
13 Replies
CoRoys
CoRoysOP2y ago
reflectronic
reflectronic2y ago
this happens every time?
CoRoys
CoRoysOP2y ago
Yeah... I'm gonna try changing architectures I swear .NET UWP is just broken at this point
reflectronic
reflectronic2y ago
a good place to start is by trying with mixed-mode debugger you would need visual studio for this
CoRoys
CoRoysOP2y ago
Mixed-mode as in enabling native-code debugging?
reflectronic
reflectronic2y ago
yeah
CoRoys
CoRoysOP2y ago
Alr
CoRoys
CoRoysOP2y ago
Got to the bottom of the call stack
CoRoys
CoRoysOP2y ago
Windows.Media.Devices.dll is the file. At this point in native debugging, you're supposed to compile a modified version of that file yourself? If anyone knows how to find the source file for bluetootha2dpplaybackconnection.cpp I'd appreciate it It'd provide a lot more insight on what's going on
reflectronic
reflectronic2y ago
sorry, didn't see this at this point you have debugged into windows source code and there isn't much you can do unless you are pretty good at reverse-engineering you'll need to black box debug this (maybe see if other devices have this problem? maybe try making your code more similar to the example in the documentation?), or find some contact at microsoft who can help you, or accept that this WinRT API is bugged like many others i am not sure how much luck you'll have, but you may want to post somewhere in $uwp that you're getting an access violation when calling this API
reflectronic
reflectronic2y ago
it should not happen, no matter how you slice it, so there's definitely a bug to be fixed, and it's almost certainly in AudioPlaybackConnection itself
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server