Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# RegexStringValidator未引发ArgumentException_C#_Visual Studio 2012_App Config - Fatal编程技术网

C# RegexStringValidator未引发ArgumentException

C# RegexStringValidator未引发ArgumentException,c#,visual-studio-2012,app-config,C#,Visual Studio 2012,App Config,我有以下代码: try { var configSection = config.GetSection("customSectionConfiguration") as CustomSection; } catch (ArgumentException ex) { throw new InvalidConfigurationException(ex); } catch (Exception) { throw; } 在我的CustomSection类中,我有一个Confi

我有以下代码:

try
{
    var configSection = config.GetSection("customSectionConfiguration") as CustomSection;
}
catch (ArgumentException ex)
{
    throw new InvalidConfigurationException(ex);
}
catch (Exception)
{
    throw;
}
在我的CustomSection类中,我有一个ConfigurationElement,其属性上有RegexStringValidator属性,如下所示:

[ConfigurationProperty("property", IsRequired=true, DefaultValue="null")]
[RegexStringValidator("^\w*$")]
public string Property {...}
现在,在我的配置文件中,我放置了一个与此正则表达式冲突的值,当我尝试加载配置(
config.GetSection(…)
)时,会按预期引发一个异常,但它不是RegexStringValidator文档所建议的ArgumentException。相反,它被通用异常捕获,并显示以下消息:“属性'property'的值无效。错误是:该值不符合验证正则表达式字符串'^\w*$'


有人知道实际抛出的异常类型吗?或者我如何在调试时确定这一类型?

遵循Paul Griffin的建议后,发现此处抛出的异常类型是ConfigurationErrorsException。我在调试时通过在watch窗口中调用ex.GetType()发现了这一点。

要快速检查,可以将泛型catch更改为
catch(异常ex)
并在catch块中放置一个断点,以调查ex的类型。这是我尝试过的,但我没有看到任何东西可以让我知道它是什么类型的异常。这次我在watch窗口中调用了ex.GetType(),解决了问题。事实证明这是一个配置错误异常。谢谢你的帮助。