Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

I've one main app (launcher) and a library containing all ui controls.

When I launch main app (.exe) I try to upgrade dll's user settings calling this method:

public static void CheckForUpgrade()
{
if (Settings1.Default.UpdateSettings)
{
Settings1.Default.Upgrade();
Settings1.Default.UpdateSettings = false;
Settings1.Default.Save();
}
}

When I review logs, i can see upgrade is called, but settings are reset to default values.

There is anyway to upgrade dll settings that it's not in the main (executing) assembly?

What I have tried:

Tried to call this method from the main app. It's defined in the external dll under an static class (SettingsManager)

public static void CheckForUpgrade()
{
  if (Settings1.Default.UpdateSettings)
  {
    Settings1.Default.Upgrade();
    Settings1.Default.UpdateSettings = false;
    Settings1.Default.Save();                    
  }
}
Posted
Updated 11-Dec-18 1:56am
v2

You need to start by doing two things:
1) Look at the code you are calling, not the code that calls it. The code you show is trivial - you need to look at what the Upgrade method actually does.
2) Use the debugger to check that the CheckForUpgrade method is called, and step through into the Upgrade and Save methods to find out exactly what they are doing. While they do it, check the files you think they should be updating (or the databases if they use them) and make sure that changes go where you expect.

Sorry, but we can't do any of that for you!
 
Share this answer
 
Comments
sortgnz 11-Dec-18 10:20am    
Hi OriginalGriff:

As I said, logs tell me that Settings1.Default.Upgrade() is called.
But upgrade() is .net framework and not custom code implemented by myself. (System.Configuration.ApplicationSettingsBase)

I read that settings upgrade is one of the first things to do when release a new assembly.
If another piece of code looks for settings1 before you try to upgrade, the upgrade fails. But is the first line of the main routine.

Thanks for your reply. Sorry my english. First time posting a question as you can see..
sortgnz 12-Dec-18 4:10am    
Overriding Upgrade() I can see the problem.
Iterating all SettingspropertyValues and getting previosversion always returns null.

public override void Upgrade()
{

foreach (System.Configuration.SettingsPropertyValue property in this.PropertyValues)
{
try
{
object PreviousValue = this.GetPreviousVersion(property.Name);

if (this.PropertyValues[property.Name] != null)
{
this.PropertyValues[property.Name].PropertyValue = PreviousValue;

}
}
catch (System.Exception ex)
{
LogManager.LogManager.Log.Error(string.Format("Error upgradding setting : {0}", property.Name), ex);
}
}

//base.Upgrade();
}
}
Found workaround here:

c# - ApplicationSettingsBase.Upgrade() Not Upgrading User Settings after Recompiling with .NET 4.0 - Stack Overflow[^]

I think the problem is user settings concurrence related to diferent release/debug versions. (version numbers not correlated, and upgrade doesn't know how to resolve)

Cleaning before testing this feature may solve it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900