c# - The method or operation is not implemented exception when trying to use custom class for user setting
问题描述
I'm trying to save window's position as a user setting so I can restore it when my app starts up. I add a setting using the designer of this type:
using System.Configuration;
namespace MyApp.Framework
{
[SettingsSerializeAs(SettingsSerializeAs.Xml)]
public class SavedWindowSettings
{
public double Left { get; set;}
public double Top { get; set;}
public SavedWindowSettings()
{ }
public SavedWindowSettings(double left, double top)
{
Left = left;
Top = top;
}
}
}
It compiles, but when I run I get System.NotImplementedException: 'The method or operation is not implemented.' on the application, but the last thing in the call stack is PresentationFramework.dll!System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(System.Windows.Baml2006.Baml2006SchemaContext.BamlType bamlType, short typeId) Unknown, which doesn't help much.
I think is has to do with App.config. If I change the type of setting to string, my App.config has a
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
and
<userSettings>
<MyApp.Properties.Settings>
<setting name="MainWindowPlacement" serializeAs="String">
<value />
</setting>
</MyApp.Properties.Settings>
</userSettings>
sections. I tried adding them back in, changing serializeAs to "xml", with the same exception. What am I missing?
解决方案
The first thing that screams out is that you have no setter's defined for Left
and Top
. Why don't you have:
public double Left { get; set; }
public double Top { get; set; }
The exception could be from the runtime reporting that there is no method for setting your props.
推荐阅读
- jquery - 使用 jQuery 向元素添加类
- xaml - Xamarin 在一行的每一端有两个标签
- python - Pygame 随机坐标生成
- wordpress - 移动版中未配置的间距元素
- javascript - 在 Google 表单中嵌入颜色选择器?
- python - R / Python置信区间
- javascript - Jmeter Chromedriver 错误:未知错误:从远程主机执行时,DevToolsActivePort 文件不存在
- php - 使用 Mysql 结果作为值
- laravel - 什么是 .phpunit.result.cache
- mysql - MySQL 通过中间表加入