internal WinRTSpellerInterop() { // When the CLR consumes an unmanaged COM object, it invokes // System.ComponentModel.LicenseManager.LicenseInteropHelper.GetCurrentContextInfo // which in turn calls Assembly.GetName. Assembly.GetName requires FileIOPermission for // access to the path of the assembly. FileIOPermission fiop = new FileIOPermission(PermissionState.None); fiop.AllLocalFiles = FileIOPermissionAccess.PathDiscovery; fiop.Assert(); try { SpellCheckerFactory.Create(shouldSuppressCOMExceptions: false); } catch (Exception ex) // Sometimes, InvalidCastException is thrown when SpellCheckerFactory fails to instantiate correctly when(ex is InvalidCastException || ex is COMException) { Dispose(); throw new PlatformNotSupportedException(string.Empty, ex); } finally { CodeAccessPermission.RevertAssert(); } _spellCheckers = new Dictionary <CultureInfo, Tuple <WordsSegmenter, SpellChecker> >(); _customDictionaryFiles = new Dictionary <string, List <string> >(); _defaultCulture = InputLanguageManager.Current?.CurrentInputLanguage ?? Thread.CurrentThread.CurrentCulture; _culture = null; try { EnsureWordBreakerAndSpellCheckerForCulture(_defaultCulture, throwOnError: true); } catch (Exception ex) when(ex is ArgumentException || ex is NotSupportedException || ex is PlatformNotSupportedException) { _spellCheckers = null; Dispose(); if ((ex is PlatformNotSupportedException) || (ex is NotSupportedException)) { throw; } else { throw new NotSupportedException(string.Empty, ex); } } // This class is only instantiated from the UI thread, so it is safe to // obtain the Dispatcher this way. _dispatcher = new WeakReference <Dispatcher>(Dispatcher.CurrentDispatcher); WeakEventManager <AppDomain, UnhandledExceptionEventArgs> .AddHandler(AppDomain.CurrentDomain, "UnhandledException", ProcessUnhandledException); }
/// <exception cref="PlatformNotSupportedException"> /// The OS platform is not supported /// </exception> /// <exception cref="NotSupportedException"> /// The OS platform is supportable, but spellchecking services are currently unavailable /// </exception> internal WinRTSpellerInterop() { try { SpellCheckerFactory.Create(shouldSuppressCOMExceptions: false); } catch (Exception ex) // Sometimes, InvalidCastException is thrown when SpellCheckerFactory fails to instantiate correctly when (ex is InvalidCastException || ex is COMException ) { Dispose(); throw new PlatformNotSupportedException(string.Empty, ex); } _spellCheckers = new Dictionary<CultureInfo, Tuple<WordsSegmenter, SpellChecker>>(); _customDictionaryFiles = new Dictionary<string, List<string>>(); _defaultCulture = InputLanguageManager.Current?.CurrentInputLanguage ?? Thread.CurrentThread.CurrentCulture; _culture = null; try { EnsureWordBreakerAndSpellCheckerForCulture(_defaultCulture, throwOnError: true); } catch (Exception ex) when (ex is ArgumentException || ex is NotSupportedException || ex is PlatformNotSupportedException) { _spellCheckers = null; Dispose(); if ((ex is PlatformNotSupportedException) || (ex is NotSupportedException)) { throw; } else { throw new NotSupportedException(string.Empty, ex); } } // This class is only instantiated from the UI thread, so it is safe to // obtain the Dispatcher this way. _dispatcher = new WeakReference<Dispatcher>(Dispatcher.CurrentDispatcher); WeakEventManager<AppDomain, UnhandledExceptionEventArgs> .AddHandler(AppDomain.CurrentDomain, "UnhandledException", ProcessUnhandledException); }
internal WinRTSpellerInterop() { new FileIOPermission(PermissionState.None) { AllLocalFiles = FileIOPermissionAccess.PathDiscovery }.Assert(); try { SpellCheckerFactory.Create(false); } catch (Exception ex) when(ex is InvalidCastException || ex is COMException) { this.Dispose(); throw new PlatformNotSupportedException(string.Empty, ex); } finally { CodeAccessPermission.RevertAssert(); } this._spellCheckers = new Dictionary <CultureInfo, Tuple <WordsSegmenter, SpellChecker> >(); this._customDictionaryFiles = new Dictionary <string, List <string> >(); InputLanguageManager inputLanguageManager = InputLanguageManager.Current; this._defaultCulture = (((inputLanguageManager != null) ? inputLanguageManager.CurrentInputLanguage : null) ?? Thread.CurrentThread.CurrentCulture); this._culture = null; try { this.EnsureWordBreakerAndSpellCheckerForCulture(this._defaultCulture, true); } catch (Exception ex2) when(ex2 is ArgumentException || ex2 is NotSupportedException || ex2 is PlatformNotSupportedException) { this._spellCheckers = null; this.Dispose(); if (ex2 is PlatformNotSupportedException || ex2 is NotSupportedException) { throw; } throw new NotSupportedException(string.Empty, ex2); } this._dispatcher = new WeakReference <Dispatcher>(Dispatcher.CurrentDispatcher); WeakEventManager <AppDomain, UnhandledExceptionEventArgs> .AddHandler(AppDomain.CurrentDomain, "UnhandledException", new EventHandler <UnhandledExceptionEventArgs>(this.ProcessUnhandledException)); }