设置中的字典抛出异常?

Dictionary in Settings throws an exception?

我想在我项目的默认 UserSettings class 中保存字典。

我在设置文件的代码中尝试了以下但失败了:

<Setting Name="MediaKeys" Type="System.Collections.ObjectModel.Dictionary&lt;System.Input.Key, System.IO.FileInfo&gt;" Scope="User">
  <Value Profile="(Default)" />
</Setting>

当我查看设置的 UI 时收到此错误消息:

Could not load file or assembly 'System.IO.FileInfo>' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

请记住,我将在另一个时间点处理整个可序列化字典,为什么我会收到此异常?即使是不可序列化的对象(比如我测试过的 FileInfo)也不会抛出这个异常。

.NET 设置不能很好地处理泛型。这就是我所做的:

[XmlRoot("dictionary")]
public class MyDictionary : SerializableDictionary<int, string>
{
}