Home > Back-end >  What has changed among two apparently identical calls?
What has changed among two apparently identical calls?

Time:12-18

I was looking at the PowerToys Text Extractor, in particular was interested in which languages were installed, and from the documentation, I got two PowerShell snippets, that puzzled me with their behaviour: here a copy/paste from my console (Italy localized)

PS C:\Users\Carlo> [Windows.Media.Ocr.OcrEngine]::AvailableRecognizerLanguages
Impossibile trovare il tipo [Windows.Media.Ocr.OcrEngine].
In riga:1 car:1
  [Windows.Media.Ocr.OcrEngine]::AvailableRecognizerLanguages
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      CategoryInfo          : InvalidOperation: (Windows.Media.Ocr.OcrEngine:TypeName) [], RuntimeException
      FullyQualifiedErrorId : TypeNotFound

PS C:\Users\Carlo> [Windows.Media.Ocr.OcrEngine, Windows.Foundation, ContentType = WindowsRuntime]

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    OcrEngine                                System.Runtime.InteropServices.WindowsRuntime.RuntimeClass


PS C:\Users\Carlo> [System.Runtime.InteropServices.WindowsRuntime.RuntimeClass]::AvailableRecognizerLanguages
Impossibile trovare il tipo [System.Runtime.InteropServices.WindowsRuntime.RuntimeClass].
In riga:1 car:1
  [System.Runtime.InteropServices.WindowsRuntime.RuntimeClass]::Availab ...
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      CategoryInfo          : InvalidOperation: (System.Runtime....me.RuntimeClass:TypeName) [], RuntimeException
      FullyQualifiedErrorId : TypeNotFound

PS C:\Users\Carlo> [Windows.Media.Ocr.OcrEngine]

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    OcrEngine                                System.Runtime.InteropServices.WindowsRuntime.RuntimeClass


PS C:\Users\Carlo> [Windows.Media.Ocr.OcrEngine]::AvailableRecognizerLanguages


DisplayName     : Inglese (Regno Unito)
LanguageTag     : en-GB
NativeName      : English (United Kingdom)
Script          : Latn
LayoutDirection : Ltr
AbbreviatedName : ENG

DisplayName     : Italiano (Italia)
LanguageTag     : it-IT
NativeName      : italiano (Italia)
Script          : Latn
LayoutDirection : Ltr
AbbreviatedName : ITA

In the end, exactly what I was expecting, but why the first invocation (or maybe query is a more precise technical term) of [Windows.Media.Ocr.OcrEngine]::AvailableRecognizerLanguages resulted in an error, but the later (apparently identical) call resulted in the correct information display ?

CodePudding user response:

Your first invocation didn't call

[Windows.Media.Ocr.OcrEngine, Windows.Foundation, ContentType = WindowsRuntime]

without this line, the command

[Windows.Media.Ocr.OcrEngine]::AvailableRecognizerLanguages

won't work.

You can reproduce it, by closing your PowerShell.

  • Related