C# UserAppDataReigstry未持久化

C# UserAppDataReigstry未持久化,c#,devexpress,registry,C#,Devexpress,Registry,我有以下类来保存我的相机设置 using System; using System.Drawing; using System.Windows.Forms; using DevExpress.XtraEditors.Camera; public class CameraDeviceHelper { public string DeviceMoniker; public string DeviceName; public i

我有以下类来保存我的相机设置

using System;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.XtraEditors.Camera;        

public class CameraDeviceHelper
    {
        public string DeviceMoniker;
        public string DeviceName;
        public int DeviceResolutionWidth;
        public int DeviceResolutionHeight;

        const string kDeviceName = "CameraDeviceName";
        const string kDeviceMoniker = "CameraDeviceMoniker";
        const string kDeviceResolutionWidth = "CameraDeviceResolutionWidth";
        const string kDeviceResolutionHeight = "CameraDeviceResolutionHeight";

        public bool SaveCameraDevice(CameraControl cc)
        {
            try
            {
                DeviceMoniker = cc.Device.DeviceMoniker;
                DeviceName = cc.Device.Name;
                DeviceResolutionWidth = cc.Device.Resolution.Width;
                DeviceResolutionHeight = cc.Device.Resolution.Height;

                Application.UserAppDataRegistry.SetValue(kDeviceName, DeviceName);
                Application.UserAppDataRegistry.SetValue(kDeviceMoniker, DeviceMoniker);
                Application.UserAppDataRegistry.SetValue(kDeviceResolutionWidth, DeviceResolutionWidth);
                Application.UserAppDataRegistry.SetValue(kDeviceResolutionHeight, DeviceResolutionHeight);

                return true;
            }
            catch (Exception)
            {
                return false;

            }

        }
        public bool RestoreCameraDevice(CameraControl cc)
        {
            try
            {
                DeviceName = Application.UserAppDataRegistry.GetValue(kDeviceName, DeviceName).ToString();
                DeviceMoniker =Application.UserAppDataRegistry.GetValue(kDeviceMoniker, DeviceMoniker).ToString();
                DeviceResolutionWidth = (int) Application.UserAppDataRegistry.GetValue(kDeviceResolutionWidth, DeviceResolutionWidth);
                DeviceResolutionHeight = (int)Application.UserAppDataRegistry.GetValue(kDeviceResolutionHeight, DeviceResolutionHeight);

                var moniker = new DevExpress.Data.Camera.CameraDeviceInfo(DeviceMoniker, DeviceName);
                cc.Device = new CameraDevice(moniker);
                var sz = new Size(DeviceResolutionWidth,DeviceResolutionHeight);
                cc.Device.Resolution = sz;
                if (cc.Device.Resolution.Width != sz.Width)
                { MessageBox.Show("Not set");}

                cc.Start();

                return true;
            }
            catch (Exception)
            {
                return false;

            }

        }
    }
}
应用程序运行时,持久化工作。 但是,当我重新启动应用程序时,设置将丢失

我在窗体的load和FormClosed事件中调用这些方法

    private void Camera_Load(object sender, EventArgs e)
    {
        textEdit1.Text = PhotoCaption;
        cameraDeviceHelper = new CameraDeviceHelper();
        try
        {
            cameraDeviceHelper.RestoreCameraDevice(cameraControl1);

        }
        catch (Exception)
        {
            // probably first time... so just dont complain
            throw;
        }

    }

    private void Camera_FormClosed(object sender, FormClosedEventArgs e)
    {
        cameraDeviceHelper.SaveCameraDevice(cameraControl1);
    }

解决方案是在AssemblyVersion中不使用*
否则,每次构建应用程序时,注册表项都将更改

显示所有相关代码。例如,您呼叫的所有位置
SaveCameraDevice
RestoreCameraDevice
。是否序列化然后返回文件?查看此链接查看我可以通过在AssemblyInfo中删除AssemblyVersion中的*使其工作。cs@MatthewFlynn我正在保存到注册表,因此不需要涉及文件