3

I'm trying to save a 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.'

but the last thing in the call stack is

PresentationFramework.dll!System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(System.Windows.Baml2006.Baml2006SchemaContext.BamlType bamlType, short typeId)

which doesn't help much. I think is has to do with App.config. If I change the type of the setting to string, my App.config has

     <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?

Hugh W
  • 716
  • 2
  • 10
  • 33
Kage
  • 563
  • 2
  • 10
  • 20
  • `NotImplementedException` sure doesn't help much! I've written up a guide on how to diagnose the underlying problem at https://stackoverflow.com/a/74460800/1688738. – Hugh W Nov 16 '22 at 13:01

2 Answers2

1

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.

T McKeown
  • 12,971
  • 1
  • 25
  • 32
-1

After much screaming, I found that somehow, one of my libs didn't work correctly after I installed PrettyBin. No idea what, where or why, I like figuring out things for my self, but I was pretty much down to trying random things. Useless error message :)

Kage
  • 563
  • 2
  • 10
  • 20
  • Can you provide more details? What was the library? What is PrettyBin? What actually fixed your problem in the end? – Hugh W Nov 15 '22 at 08:21