Localized speech recognition throwing ArgumentException - c#

I have the following problem:
I am using a German Windows7-machine (Culture: "de-DE"), but I want to use the SpeechRecognitionEngine-class with an other culture.
However, the following code throws an ArgumentException:
using (SpeechRecognitionEngine rec = new SpeechRecognitionEngine(new CultureInfo("en-GB"))) //ArgumentException
{
rec.LoadGrammar(new DictationGrammar("grammar:dictation#spelling"));
rec.SpeechRecognized += rec_SpeechRecognized;
rec.SetInputToDefaultAudioDevice();
rec.RecognizeAsync(RecognizeMode.Multiple);
...
}
The Exception message is the following:
Es wurde kein Erkennungsmodul mit der erforderlichen ID gefunden.
Translation:
No recognition module with the required ID could be found.
Does this mean, that some sort of language package is missing on my machine?

I suggest the en-GB-packet has to be installed on the machine.
EDIT:
It would be also reasonable to use a try catch block to prevent the app from crashing if the packet is not available.

Related

excel interop unable to start server exception after several calls

I have an asp.net MVC Webapplication who uses the excel interop to open a csv in an excel save the file as an xlsx and load the bytes from that file. These bytes are then passed as a download.
So far everything works as expected. but after the 6 download I get the following exception. Unfortunately it's on german, since the server is setup in german. But the exception message is something like "80080005 starting the server failed".
Die COM-Klassenfactory für die Komponente mit CLSID {00024500-0000-0000-C000-000000000046} konnte aufgrund des folgenden Fehlers nicht abgerufen werden: 80080005 Starten des Servers fehlgeschlagen (Ausnahme von HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
Beschreibung: Unbehandelte Ausnahme beim Ausführen der aktuellen Webanforderung. Überprüfen Sie die Stapelüberwachung, um weitere Informationen über diesen Fehler anzuzeigen und festzustellen, wo der Fehler im Code verursacht wurde.
Ausnahmedetails: System.Runtime.InteropServices.COMException: Die COM-Klassenfactory für die Komponente mit CLSID {00024500-0000-0000-C000-000000000046} konnte aufgrund des folgenden Fehlers nicht abgerufen werden: 80080005 Starten des Servers fehlgeschlagen (Ausnahme von HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
When I restart the website, it works again for the next 5-7 downloads.
here is my code for the excel:
private byte[] WriteExcel(SelectionResult result)
{
var csvPath = Path.Combine(Settings.Default.FileGenerationPath, DateTime.Now.ToString("yyMMMddhhmmss") + "_" +new Random().Next(1000, 9999)+".csv");
var excelPath = Path.Combine(Settings.Default.FileGenerationPath, DateTime.Now.ToString("yyMMMddhhmmss") + "_" + new Random().Next(1000, 9999)+".xlsx");
var excelApp = new Application();
File.WriteAllBytes(csvPath, WriteCsv(result, true));
var excelWorkbooks = excelApp.Workbooks;
excelWorkbooks.Open(csvPath, Delimiter: ",");
var workbook = excelApp.ActiveWorkbook;
workbook.SaveAs(excelPath, XlFileFormat.xlOpenXMLWorkbook);
excelWorkbooks.Close();
excelApp.Quit();
var bytes = File.ReadAllBytes(excelPath);
File.Delete(csvPath);
File.Delete(excelPath);
return bytes;
}
What do I miss?
According to Microsoft Support, that kind of error
You may receive an "Error code 80080005 -- server execution failed." error message when you start many COM+ applications
arise when you are using too many com applications. And you have a pretty much not disposed unmanaged resources. Every time use using statement in you are using input-output operations.
Update No. You don't. Closing an Excel is not releasing COM object while the application is running.
You need to:
//include marshal
using System.Runtime.InteropServices;
//release objects
Marshal.ReleaseComObject(excelApp);
Marshal.ReleaseComObject(excelWorkbooks);
Marshal.ReleaseComObject(workbook);

C# Limit Error when requesting E-Mails using MAPI

Always when I request E-Mails from my Outlook, which uses Office365 a COM-Exception is thrown, after a count of mails. I really have no idea why...
Error:
System.Runtime.InteropServices.COMException (0xBFE40305):
Die Anzahl der Elemente, die gleichzeitig geöffnet werden können, wurde vom Serveradministrator begrenzt.
Schließen Sie zunächst geöffnete Nachrichten, oder entfernen Sie Anhänge und Bilder von
ungesendeten Nachrichten, die Sie gerade verfassen.
bei Microsoft.Office.Interop.Outlook._MailItem.get_Recipients()
.....
For the people that don't speak German, it means:
The count of the elements which could be opened at the same time, is limited by the server administrator (....)
I don't know anything about such a Limit, and the solution which I can find on Google or MSDN don't help ether.
It looks like it crashes when the program tries to get the E-Mail recipients. Here is the way, how I try to get the Recipients:
foreach (var item in SelectedFolder.Items.Restrict(filter))
{
Outlook.MailItem mail = item as Outlook.MailItem;
if (mail != null)
{
if (mail.Recipients.Count > 0)
{
string caption = mail.Subject;
string MAIL = mail.Recipients[1].PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E"); //<--- CRASH HERE
I really don't understand, how this can happen, as far I know, when I select E-Mails from Outlook, they just get "opened" local... So I can't get, how a "Server-Limit" can access to this.
In the online mode the number of simultaneously open objects is limited by the Exchange provider (since each object opens a separate RPC channel).
For the messages, the limit is 255 by default.
Do not use a foreach loop - it will keep each member of the loop referenced until the loop exits. Use a for loop and explicitly release the item (and all of its subjects that you retrieved, such as recipients or attachments) at the end of each iteration using Marshal.ReleaseComObject(). Avoid using multiple dot notation as that forces the compiler to create implicit variables that you cannot explicitly release.
Also keep in mind that the as operator also produces an implicit variable - break that line into two and release both variables using Marshal.ReleaseComObject()

Retrieving calls history from Windows 10 app - Access denied error

I'm trying to collect the Windows Mobile 10 calls history by using the latest API. I have enabled all possible capabilities for my application, but still I'm getting "Access Denied" error while running this code:
var operation = PhoneCallHistoryManager.RequestStoreAsync(PhoneCallHistoryStoreAccessType.AppEntriesReadWrite);
operation.Completed = (o, ev) =>
{
PhoneCallHistoryStore store = o.GetResults();
PhoneCallHistoryEntryReader reader = store.GetEntryReader();
var operation2 = reader.ReadBatchAsync();
operation2.Completed = (o2, ev2) =>
{
IReadOnlyList<PhoneCallHistoryEntry> callsList = o2.GetResults();
foreach (PhoneCallHistoryEntry entry in callsList)
{
// process calls here
}
};
};
I'm getting the following error message while doing line 4:
An exception of type 'System.UnauthorizedAccessException' occurred in App1.exe but was not handled in user code
Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
I'm running this code on Mobile Emulator in Visual Studio 2015.
This is what I used for that code:
https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.calls.aspx
Any idea what can be wrong?
In order to make above code working and view phone call history, need to add the following things:
1) Rescap namespace
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
2) Restricted capability "phoneCallHistory"
<rescap:Capability Name="phoneCallHistory"/>
3) Change PhoneCallHistoryAccessType to AllEntriesLimitedReadAndWrite.
var operation = PhoneCallHistoryManager.RequestStoreAsync(PhoneCallHistoryStoreAccessType.AllEntriesLimitedReadWrite);
Thanks to #RaymondChen for giving me the proper capability name.

Saving more than one entity at once

I'm working with Entity Framework 5 and a MySQL DB and I'd like to save two new related entities at once:
var record = data.Records.Create();
record.Name = "Abbey Road";
data.Records.Add(record);
// Create the song
var song = data.Songs.Create();
song.Title = "Here Comes The Sun";
song.Record = record;
data.Songs.Add(song);
data.SaveChanges();
But it fails. The exception is:
System.Data.Entity.Infrastructure.DbUpdateException : Fehler beim Aktualisieren der Einträge. Weitere Informationen finden Sie in der internen Ausnahme.
----> System.Data.UpdateException : Fehler beim Aktualisieren der Einträge. Weitere Informationen finden Sie in der internen Ausnahme.
----> System.ArgumentException : Der angegebene Wert ist keine Instanz eines gültigen Konstantentyps.
Parametername: value
English Translation
System.Data.Entity.Infrastructure.DbUpdateException: Failed to update the entries. See the inner exception. ---> System.Data.UpdateException: failed to update the entries. See the inner exception. ---> System.ArgumentException: value specified is not a valid constant type an instance. Parameter name: value
Sorry, it's German. The first exception means the given value is not a valid type of constant. It looks like that the provider (mysql) wants to update something where it should use an insert.
Does anybody have an idea what it is?
Best regards,
Torsten
There are a lot of similar problems in combination with mySQL. Try change any unsigned columns in mysql to signed. EF doesn't support unsigned.
Hope this helps

SpeechRecognitionEngine.InstalledRecognizers returns No recognizer installed

I am trying to get a simple speech recognition program started but it does not work, I've installed some languages (en-GB & en-US) but whenever I use the following:
SpeechRecognitionEngine.InstalledRecognizers
it returns an empty collection. Even when I just try to start a recognizer it will return "no recognizer installed". But when I reinstall a language, it says that it is already installed.
using ( SpeechRecognitionEngine recognizer = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("en-US")))
{
// Create and load a dictation grammar.
recognizer.LoadGrammar(new DictationGrammar());
// Add a handler for the speech recognized event.
recognizer.SpeechRecognized +=
new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);
// Configure input to the speech recognizer.
recognizer.SetInputToDefaultAudioDevice();
// Start asynchronous, continuous speech recognition.
recognizer.RecognizeAsync(RecognizeMode.Multiple);
// Keep the console window open.
while (true)
{
Console.ReadLine();
}
}
For what reason is it unable to find the installed recognizers?
Edit:
This is the exception: {System.ArgumentException: No recognizer of the required ID found.
Parameter name: culture
at System.Speech.Recognition.SpeechRecognitionEngine..ctor(CultureInfo culture)
and: var recognizers = SpeechRecognitionEngine.InstalledRecognizers(); returns a collection with a count of 0
The problem was that I installed language packs that can be accessed by Microsoft.Speech and I was using System.Speech, when I switched to Microsoft.Speech it worked.

Categories

Resources