{"record":{"id":"36d27f224ce23b91","repo":"microsoft/semantic-kernel","slug":"invalid-execution-settings-cannot-convert-to-nam","errorCode":null,"errorMessage":"Invalid execution settings, cannot convert to {nameof(AzureAIInferencePromptExecutionSettings)}","messagePattern":"Invalid execution settings, cannot convert to (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.AzureAIInference/Settings/AzureAIInferencePromptExecutionSettings.cs","lineNumber":264,"sourceCode":"        if (executionSettings is null)\n        {\n            return new AzureAIInferencePromptExecutionSettings();\n        }\n\n        if (executionSettings is AzureAIInferencePromptExecutionSettings settings)\n        {\n            return settings;\n        }\n\n        var json = JsonSerializer.Serialize(executionSettings);\n\n        var aiInferenceSettings = JsonSerializer.Deserialize<AzureAIInferencePromptExecutionSettings>(json, JsonOptionsCache.ReadPermissive);\n        if (aiInferenceSettings is not null)\n        {\n            return aiInferenceSettings;\n        }\n\n        throw new ArgumentException($\"Invalid execution settings, cannot convert to {nameof(AzureAIInferencePromptExecutionSettings)}\", nameof(executionSettings));\n    }\n\n    #region private ================================================================================\n\n    private string? _extraParameters;\n    private float? _frequencyPenalty;\n    private float? _presencePenalty;\n    private float? _temperature;\n    private float? _nucleusSamplingFactor;\n    private int? _maxTokens;\n    private object? _responseFormat;\n    private IList<string>? _stopSequences;\n    private IList<ChatCompletionsToolDefinition>? _tools;\n    private long? _seed;\n\n    #endregion\n}\n","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.AzureAIInference/Settings/AzureAIInferencePromptExecutionSettings.cs#L246-L282","documentation":"Thrown by AzureAIInferencePromptExecutionSettings.FromExecutionSettings when an incoming PromptExecutionSettings cannot be converted. Conversion first short-circuits for null and same-type inputs, then serializes the object to JSON and deserializes into AzureAIInferencePromptExecutionSettings using JsonOptionsCache.ReadPermissive. If that deserialization yields null, an ArgumentException is thrown.","triggerScenarios":"Passing an execution settings instance whose JSON serialization deserializes to null for AzureAIInferencePromptExecutionSettings — e.g. a malformed ExtensionData, a settings subclass with incompatible constructor/property shapes, or a Dictionary-backed settings whose JSON root is not an object. Also from a config file where the settings node cannot bind.","commonSituations":"Hand-constructing a PromptExecutionSettings from an anonymous/dictionary object whose JSON form is empty or non-object. Loading settings from YAML/JSON config where the node is missing or null. Passing an OpenAI-specific settings object with fields that fail permissive binding.","solutions":["Construct an AzureAIInferencePromptExecutionSettings directly instead of relying on cross-type conversion.","Ensure the source settings object JSON-serializes to a non-null JSON object with known properties.","If loading from config, validate the settings node exists and is an object before FromExecutionSettings.","Catch ArgumentException around settings conversion and provide a clear configuration error."],"exampleFix":"// before\nvar settings = PromptExecutionSettings.FromDictionary(configDict);\nvar azure = AzureAIInferencePromptExecutionSettings.FromExecutionSettings(settings);\n// throws if configDict deserializes to null\n\n// after\nvar azure = new AzureAIInferencePromptExecutionSettings\n{\n    Temperature = 0.7f,\n    MaxTokens = 512\n};","handlingStrategy":"validation","validationCode":"// pre-flight: ensure the settings JSON is a non-null object\nvar json = JsonSerializer.Serialize(executionSettings);\nusing var doc = JsonDocument.Parse(json);\nif (doc.RootElement.ValueKind != JsonValueKind.Object)\n    throw new ArgumentException(\"Execution settings must serialize to a JSON object.\");\nvar azure = AzureAIInferencePromptExecutionSettings.FromExecutionSettings(executionSettings);","typeGuard":"bool IsConvertibleToAzureAI(PromptExecutionSettings? s)\n{\n    if (s is null || s is AzureAIInferencePromptExecutionSettings) return true;\n    var json = JsonSerializer.Serialize(s);\n    using var doc = JsonDocument.Parse(json);\n    return doc.RootElement.ValueKind == JsonValueKind.Object;\n}","tryCatchPattern":"try { return AzureAIInferencePromptExecutionSettings.FromExecutionSettings(settings); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"cannot convert to AzureAIInferencePromptExecutionSettings\"))\n{ throw new ConfigurationException(\"Execution settings could not be converted to AzureAIInferencePromptExecutionSettings.\", ex); }","preventionTips":["Prefer constructing AzureAIInferencePromptExecutionSettings directly.","Validate config-sourced settings nodes are JSON objects before conversion.","Catch ArgumentException and surface the original settings source for debugging."],"tags":["azure-ai-inference","execution-settings","configuration","csharp"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}