Skip to content
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

Handle a null szPname field #75695

Merged
merged 4 commits into from
Sep 15, 2022
Merged

Handle a null szPname field #75695

merged 4 commits into from
Sep 15, 2022

Conversation

jkoritzinsky
Copy link
Member

Fixes #75667

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented Sep 15, 2022

Tagging subscribers to this area: @danmoseley
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #75667

Author: jkoritzinsky
Assignees: jkoritzinsky
Labels:

area-System.Speech

Milestone: -

@danmoseley
Copy link
Member

danmoseley commented Sep 15, 2022

If you add a call before this line


to synth.SetOutputToDefaultAudioDevice() does it repro it? If so maybe throw that in this PR?

@jkoritzinsky
Copy link
Member Author

@danmoseley should I start a backport for this PR?

@stephentoub stephentoub merged commit 1bb1629 into main Sep 15, 2022
@stephentoub
Copy link
Member

/backport to release/7.0

@stephentoub stephentoub deleted the waveoutcaps-null-ref branch September 15, 2022 20:42
@github-actions
Copy link
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3063572266

@stephentoub
Copy link
Member

/backport to release/7.0-rc2

@github-actions
Copy link
Contributor

Started backporting to release/7.0-rc2: https://github.com/dotnet/runtime/actions/runs/3063574386

@stephentoub
Copy link
Member

@jkoritzinsky, were you able to repro the exception before the fix and validate it doesn't repro after?

@jkoritzinsky
Copy link
Member Author

I wasn't able to repro it initially, but based on the stack trace this was the only possible location for the exception.

I'll try reproing it without the fix again if that will help for servicing.

@stephentoub
Copy link
Member

stephentoub commented Sep 15, 2022

It'd help both with servicing and with confidence that we actually fixed the problem.

@jkoritzinsky
Copy link
Member Author

I can't get it to repro locally on my machine. It's possible I didn't configure something right on the Windows side as there's some Windows configuration for System.Speech that I had to go through before any of the tests would run.

@danmoseley
Copy link
Member

danmoseley commented Sep 15, 2022

This code is pretty dependent on OS state, thinking back to bugs we've seen. I know that it can depend on eg what voices you have installed for what cultures and other registry settings and maybe audio device configuration. Perhaps it would be OK if you can just set szPname to null in the debugger and then run.

@jkoritzinsky
Copy link
Member Author

It looks like we won't even hit this code path if the following registry key isn't set: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Speech\AudioOutput\DefaultTokenId. I'm not sure how to manually set that registry key, so I can't repro this locally. @danmoseley any chance you have steps I can follow to set up the right key/value? (The call on line 48 below is what leads to the code that caused the exception).

internal static int DefaultDeviceOut()
{
int device = -1;
using (ObjectTokenCategory tokenCategory = ObjectTokenCategory.Create(@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Speech\AudioOutput"))
{
if (tokenCategory != null)
{
string deviceName;
if (tokenCategory.TryGetString(_defaultTokenIdValueName, out deviceName))
{
int pos = deviceName.IndexOf('\\');
if (pos > 0 && pos < deviceName.Length)
{
using (RegistryDataKey deviceKey = RegistryDataKey.Create(deviceName.Substring(pos + 1), Registry.LocalMachine))
{
if (deviceKey != null)
{
device = AudioDeviceOut.GetDevicedId(deviceKey.Name);
}
}
}
}
}
}
return device;
}

@jkoritzinsky
Copy link
Member Author

Figured out which control panel setting to set that key.

Repro'd locally without the fix and verified the fix locally.

@danmoseley
Copy link
Member

Ha, yes there's an example of the zillion registry settings

@ghost ghost locked as resolved and limited conversation to collaborators Oct 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System.NullReferenceException when using System.Speech 7.0.0-rc.1.22426.10 from Windows Forms
3 participants