diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs b/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs index 812d3c3c61..200d8a13d8 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs @@ -84,6 +84,11 @@ namespace Microsoft.ML.OnnxRuntime.Tests Assert.Throws(() => { opt.GraphOptimizationLevel = (GraphOptimizationLevel)10; }); + opt.AddSessionConfigEntry("key", "value"); + + var ex = Assert.Throws(() => { opt.AddSessionConfigEntry("", "invalid key"); }); + Assert.Contains("[ErrorCode:InvalidArgument] Config key is empty", ex.Message); + opt.AppendExecutionProvider_CPU(1); #if USE_DNNL opt.AppendExecutionProvider_Dnnl(0); diff --git a/onnxruntime/core/framework/session_options.cc b/onnxruntime/core/framework/session_options.cc index cafc1932d1..81637faec2 100644 --- a/onnxruntime/core/framework/session_options.cc +++ b/onnxruntime/core/framework/session_options.cc @@ -28,11 +28,11 @@ const std::string SessionOptions::GetConfigOrDefault(const std::string& config_k Status SessionOptions::AddConfigEntry(const char* config_key, const char* config_value) noexcept { std::string key(config_key); if (key.empty() || key.length() > 128) - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "config_key is empty or longer than maximum length 128"); + return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Config key is empty or longer than maximum length 128"); std::string val(config_value); if (val.length() > 1024) - return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "config_value is longer than maximum length 1024"); + return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Config value is longer than maximum length 1024"); auto iter = session_configurations.find(config_key); if (iter != session_configurations.cend()) {