Amazon Translate Formality Setting Not Working - .Net

0

When making the following call, I get an "Object reference note set to an instance of an object" - is there a problem with my code or how the .Net implementation was created? I'm using 3.7.5.35 and this also happens when trying request.Setting.Profanity:

Note: This is not an Async call - if it were, I would expect to get an InvalidRequestException instead of System.NullReferenceException (-2147467261)

Sample part of the code where the error gets thrown (last line):

using (var client = new AmazonTranslateClient(awsCredentials, selectedRegion))
                    {
                        var request = new Amazon.Translate.Model.TranslateTextRequest();
                        request.Text = toTranslate;
                        request.SourceLanguageCode = sourceLanguage; // SourceLanguageItem.LanguageCode;
                        request.TargetLanguageCode = translateLanguage; // TranslateLanguageItem.LanguageCode;
                        request.Settings.Formality = "FORMAL";
vabtm
asked 2 months ago27 views
1 Answer
0

Updated code with solution that works for me:

using (var client = new AmazonTranslateClient(awsCredentials, selectedRegion))
                    {
                        var request = new Amazon.Translate.Model.TranslateTextRequest();
                        request.Text = toTranslate;
                        request.SourceLanguageCode = sourceLanguage; // SourceLanguageItem.LanguageCode;
                        request.TargetLanguageCode = translateLanguage; // TranslateLanguageItem.LanguageCode;
                        
                        TranslationSettings settings = new TranslationSettings();
                        settings.Formality = "FORMAL";
                        request.Settings = settings;
vabtm
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions