Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions MahApps.Metro/Controls/WindowSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,17 @@ public bool UpgradeSettings
{
get
{
if (this["UpgradeSettings"] != null)
try
{
return (bool)this["UpgradeSettings"];
if (this["UpgradeSettings"] != null)
{
return (bool)this["UpgradeSettings"];
}
}
catch (ConfigurationErrorsException ex)
{
var filename = ((ConfigurationErrorsException)ex.InnerException).Filename;
throw new MahAppsException(string.Format("The settings file {0} seems to be corrupted", filename), ex);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think MahApps should not delete any stuff. instead we should clearly say what is going wrong. so you can use the new MahAppsException, so you can handle this in your application and tell the user, that he must delete their config file.

MahAppsException -> https://github.com/MahApps/MahApps.Metro/blob/master/MahApps.Metro/MahAppsException.cs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for my nitpicking ;-) but why must the inner exception cast to ConfigurationErrorsException? the ex is already a ConfigurationErrorsException?

should this better so?

catch (ConfigurationErrorsException ex)
{
    var filename = ex.Filename;
    throw new MahAppsException(string.Format("The settings file {0} seems to be corrupted", filename), ex.InnerException);
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes they are the same exception type but in the outer exception Filename is null. You really have to go to the InnerException and cast it… I just debugged the code again to be sure about that.

Von: Jan Karger [mailto:[email protected]]
Gesendet: Freitag, 4. September 2015 21:24
An: MahApps/MahApps.Metro [email protected]
Cc: Markus [email protected]
Betreff: Re: [MahApps.Metro] If the user.config file is corrupt the whole application crashes (#2112)

In MahApps.Metro/Controls/WindowSettings.cs #2112 (comment) :

             {
  •                return (bool)this["UpgradeSettings"];
    
  •                if (this["UpgradeSettings"] != null)
    
  •                {
    
  •                    return (bool)this["UpgradeSettings"];
    
  •                }
    
  •            }
    
  •            catch (ConfigurationErrorsException ex)
    
  •            {
    
  •                var filename = ((ConfigurationErrorsException)ex.InnerException).Filename;
    
  •                throw new MahAppsException(string.Format("The settings file {0} seems to be corrupted", filename), ex);
             }
    

sorry for my nitpicking ;-) but why must the inner exception cast to ConfigurationErrorsException? the ex is already a ConfigurationErrorsException?

should this better so?

catch (ConfigurationErrorsException ex)
{
var filename = ex.Filename;
throw new MahAppsException(string.Format("The settings file {0} seems to be corrupted", filename), ex.InnerException);
}


Reply to this email directly or view it on GitHub https://github.com/MahApps/MahApps.Metro/pull/2112/files#r38785880 . https://github.com/notifications/beacon/AD73r6m86DZcFr3Smn9bz9rsLANCtqnRks5ouedigaJpZM4F3__-.gif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Remolutionary ok, really don't know this, so i think this could be a final solution

catch (ConfigurationErrorsException ex)
{
    var innerEx = ex.InnerException as ConfigurationErrorsException;
    var filename = innerEx != null ? innerError.Filename : "<unknown>";
    throw new MahAppsException(string.Format("The settings file '{0}' seems to be corrupted", filename), ex.InnerException);
}

thx

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer more robust code like this:

catch (ConfigurationErrorsException ex)
{
    string filename = null;
    while (ex != null && (filename = ex.Filename) == null)
    {
        ex = ex.InnerException as ConfigurationErrorsException;
    }
    throw new MahAppsException(string.Format("The settings file '{0}' seems to be corrupted", filename ?? "<unknown>"), ex);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thoemmi 👍

return true;
}
Expand Down
1 change: 1 addition & 0 deletions MahApps.Metro/MahApps.Metro.NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\NET45\System.Windows.Interactivity.dll</HintPath>
Expand Down
1 change: 1 addition & 0 deletions MahApps.Metro/MahApps.Metro.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Lib\NET40\System.Windows.Interactivity.dll</HintPath>
Expand Down
1 change: 1 addition & 0 deletions samples/MetroDemo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
d:DataContext="{d:DesignInstance MetroDemo:MainWindowViewModel}"
Closing="MetroWindow_Closing"
Dialog:DialogParticipation.Register="{Binding}"
SaveWindowPosition="True"
>

<Window.Resources>
Expand Down