C
C#13mo ago
CrumpetMan

❔ 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
CrumpetMan
CrumpetMan13mo ago
reflectronic
reflectronic13mo ago
this happens every time?
CrumpetMan
CrumpetMan13mo ago
Yeah... I'm gonna try changing architectures I swear .NET UWP is just broken at this point
reflectronic
reflectronic13mo ago
a good place to start is by trying with mixed-mode debugger you would need visual studio for this
CrumpetMan
CrumpetMan13mo ago
Mixed-mode as in enabling native-code debugging?
reflectronic
reflectronic13mo ago
yeah
CrumpetMan
CrumpetMan13mo ago
Alr
CrumpetMan
CrumpetMan13mo ago
Got to the bottom of the call stack
CrumpetMan
CrumpetMan13mo 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
reflectronic13mo 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
reflectronic13mo 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
Accord13mo 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
More Posts