Windows.Media.SpeechSynthesis.SpeechSynthesizer constructor throws file not found exception

ac-lap 71 Reputation points
2021-01-14T17:19:02.807+00:00

A lot of users for my UWP app are hitting System.IO.FileNotFoundException in the Windows.Media.SpeechSynthesis.SpeechSynthesizer..ctor()

The code is calling the default constructor of Windows.Media.SpeechSynthesis.SpeechSynthesizer

private SpeechSynthesizer _speechSynthesizer = new SpeechSynthesizer();

I have got the following stack trace for one user, others also report similar stack trace. I don't hit this exception on my local machine so not able to debug further.

Any idea how can I debug this further or fix it?

System.IO.FileNotFoundException
The system cannot find the file specified.

at System.Runtime.InteropServices.McgMarshal.ActivateInstance(String) + 0x17b
   at Windows.Media.SpeechSynthesis.SpeechSynthesizer..ctor() + 0x1c
   at SampleReader.TtsHelper.TtsHelper..ctor(TtsData, MediaElement) + 0x6f
   at SampleReader.UIPages.Reader.<InitializeReader>d__45.MoveNext() + 0xfb
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x21
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__7_0(Object) + 0x1e
   at System.Action`1.Invoke(T) + 0x28
   at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore() + 0x33
   at System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32, RuntimeTypeHandle) + 0x21
   at __Interop.ComCallHelpers.Call(__ComObject, RuntimeTypeHandle, Int32) + 0xb8
   at __Interop.ForwardComStubs.Stub_19[TThis](__ComObject, Int32) + 0x24
   at Microsoft.AppCenter.Utils.ApplicationLifecycleHelper.<.ctor>b__17_1(Object, UnhandledErrorDetectedEventArgs) + 0x3d
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x21
   at Microsoft.AppCenter.Utils.ApplicationLifecycleHelper.<.ctor>b__17_1(Object, UnhandledErrorDetectedEventArgs) + 0x75
   at System.EventHandler`1.Invoke(Object, TEventArgs) + 0x2e
   at __Interop.Intrinsics.HasThisCall__24[TArg0](Object, IntPtr, Object, TArg0) + 0x36
   at Sample Reader!<BaseAddress>+0x110b4f0
Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,310 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yan Gu - MSFT 2,676 Reputation points
    2021-01-15T06:01:18.967+00:00

    Hello,

    Welcome to Microsoft Q&A.

    I tested the code above, and encountered the same exception(file not found).

    You could let your users check if the Speech Recognize feature is enabled in local machine(type Speech Recognize in Search box). And check if the language used(such as English(United States)) enables Speech(Open Setting > Time & Language > Language > Preferred languages, click English(United States) > Options).
    If the Speech Recognize feature is not supported, you need to enable it.

    There are two way you could try to enable the feature:

    1. Find your language in Language (Settings > Time & Language), click Options, click Download button under Speech to enable the Speech feature for the language.
    2. Open Speech (Settings > Time & Language), click Add voices under Manage voices, select needed language to Add.

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.