Application settings, when is it deserialized?

B

blekros

Group,

Using VS2005, VB.NET and .NET 2.0 Framework, I have a built a
mylib.dll class library. It is registered for COM interop. I have an
associated app.config. I build mylib project and get mylib.dll,
mylib.tlb, and mylib.dll.config. So far, so good.

I change the value of my setting in mylib.dll.config, using notepad.
I run a container app, which loads the COM wrapper, which should load
the .dll.config file and initialize my settings instance from
the .ddl.config file at SOME time. When is this time?

When I use a method in the library, I expect it to load my manually-
edited application setting, but instead, the value is what the code
was compiled with. Specifically, the default value specified in the
attribute on the settings.designer.vb for the property I'm using.

Here is the entirety of the generated class, settings.vb:

Namespace My

'This class allows you to handle specific events on the settings
class:
' The SettingChanging event is raised before a setting's value is
changed.
' The PropertyChanged event is raised after a setting's value is
changed.
' The SettingsLoaded event is raised after the setting values are
loaded.
' The SettingsSaving event is raised before the setting values are
saved.
Partial Friend NotInheritable Class MySettings
End Class
End Namespace


Where is a load /deserialization method for the .dll.config? Where is
the other part of the partial class?

Below is the entirety of settings.designer.vb. Where is the load /
deserialization taking place?

Am I supposed to implement the SettingsLoaded event and read it from
the .dll.config XML myself?

This appears to be a singleton object instantiated with a "new"
statement. There is no constructor that loads any file that is
obvious.

I've been waiting for this feature for a few years and would love to
use it. But, I don't see how it works. I don't see how it CAN work.
And, in fact, it is observed NOT TO WORK! {weeping, teeth gnashing}

What have a missed? It has to be something simple and obvious.

Thanks in advance,

Brad




'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:2.0.50727.832
'
' Changes to this file may cause incorrect behavior and will be
lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Option Strict On
Option Explicit On


Namespace My


<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(),
_

Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator",
"8.0.0.0"), _

Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
_
Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase

Private Shared defaultInstance As MySettings =
CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New
MySettings),MySettings)

#Region "My.Settings Auto-Save Functionality"
#If _MyType = "WindowsForms" Then
Private Shared addedHandler As Boolean

Private Shared addedHandlerLockObject As New Object

<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
_
Private Shared Sub AutoSaveSettings(ByVal sender As
Global.System.Object, ByVal e As Global.System.EventArgs)
If My.Application.SaveMySettingsOnExit Then
My.Settings.Save()
End If
End Sub
#End If
#End Region

Public Shared ReadOnly Property [Default]() As MySettings
Get

#If _MyType = "WindowsForms" Then
If Not addedHandler Then
SyncLock addedHandlerLockObject
If Not addedHandler Then
AddHandler My.Application.Shutdown,
AddressOf AutoSaveSettings
addedHandler = True
End If
End SyncLock
End If
#End If
Return defaultInstance
End Get
End Property


<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _

Global.System.Configuration.SpecialSettingAttribute(Global.System.Configuration.SpecialSetting.WebServiceUrl),
_

Global.System.Configuration.DefaultSettingValueAttribute("http://
webservicehostname/virtualdirectory/LookupService.asmx")> _
Public ReadOnly Property
AWCDisplayDocumentCmd_remoteDocMgr_DBGateway() As String
Get
Return
CType(Me("AWCDisplayDocumentCmd_remoteDocMgr_DBGateway"),String)
End Get
End Property
End Class
End Namespace

Namespace My

<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _

Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()>
_
Friend Module MySettingsProperty


<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")>
_
Friend ReadOnly Property Settings() As
Global.AWCArcMapCommand.My.MySettings
Get
Return Global.AWCArcMapCommand.My.MySettings.Default
End Get
End Property
End Module
End Namespace
 
K

Kevin Spencer

Hi Brad,

When a DLl is sed by an application, it is running under the application's
context, and it is the application's configuration file that will be used.
Just add the necessary settings to the application's configuration file and
the DLL will use them.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

blekros said:
Group,

Using VS2005, VB.NET and .NET 2.0 Framework, I have a built a
mylib.dll class library. It is registered for COM interop. I have an
associated app.config. I build mylib project and get mylib.dll,
mylib.tlb, and mylib.dll.config. So far, so good.

I change the value of my setting in mylib.dll.config, using notepad.
I run a container app, which loads the COM wrapper, which should load
the .dll.config file and initialize my settings instance from
the .ddl.config file at SOME time. When is this time?

When I use a method in the library, I expect it to load my manually-
edited application setting, but instead, the value is what the code
was compiled with. Specifically, the default value specified in the
attribute on the settings.designer.vb for the property I'm using.

Here is the entirety of the generated class, settings.vb:

Namespace My

'This class allows you to handle specific events on the settings
class:
' The SettingChanging event is raised before a setting's value is
changed.
' The PropertyChanged event is raised after a setting's value is
changed.
' The SettingsLoaded event is raised after the setting values are
loaded.
' The SettingsSaving event is raised before the setting values are
saved.
Partial Friend NotInheritable Class MySettings
End Class
End Namespace


Where is a load /deserialization method for the .dll.config? Where is
the other part of the partial class?

Below is the entirety of settings.designer.vb. Where is the load /
deserialization taking place?

Am I supposed to implement the SettingsLoaded event and read it from
the .dll.config XML myself?

This appears to be a singleton object instantiated with a "new"
statement. There is no constructor that loads any file that is
obvious.

I've been waiting for this feature for a few years and would love to
use it. But, I don't see how it works. I don't see how it CAN work.
And, in fact, it is observed NOT TO WORK! {weeping, teeth gnashing}

What have a missed? It has to be something simple and obvious.

Thanks in advance,

Brad




'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:2.0.50727.832
'
' Changes to this file may cause incorrect behavior and will be
lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Option Strict On
Option Explicit On


Namespace My


<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(),
_

Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator",
"8.0.0.0"), _

Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
_
Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase

Private Shared defaultInstance As MySettings =
CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New
MySettings),MySettings)

#Region "My.Settings Auto-Save Functionality"
#If _MyType = "WindowsForms" Then
Private Shared addedHandler As Boolean

Private Shared addedHandlerLockObject As New Object

<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
_
Private Shared Sub AutoSaveSettings(ByVal sender As
Global.System.Object, ByVal e As Global.System.EventArgs)
If My.Application.SaveMySettingsOnExit Then
My.Settings.Save()
End If
End Sub
#End If
#End Region

Public Shared ReadOnly Property [Default]() As MySettings
Get

#If _MyType = "WindowsForms" Then
If Not addedHandler Then
SyncLock addedHandlerLockObject
If Not addedHandler Then
AddHandler My.Application.Shutdown,
AddressOf AutoSaveSettings
addedHandler = True
End If
End SyncLock
End If
#End If
Return defaultInstance
End Get
End Property


<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _

Global.System.Configuration.SpecialSettingAttribute(Global.System.Configuration.SpecialSetting.WebServiceUrl),
_

Global.System.Configuration.DefaultSettingValueAttribute("http://
webservicehostname/virtualdirectory/LookupService.asmx")> _
Public ReadOnly Property
AWCDisplayDocumentCmd_remoteDocMgr_DBGateway() As String
Get
Return
CType(Me("AWCDisplayDocumentCmd_remoteDocMgr_DBGateway"),String)
End Get
End Property
End Class
End Namespace

Namespace My

<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _

Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()>
_
Friend Module MySettingsProperty


<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")>
_
Friend ReadOnly Property Settings() As
Global.AWCArcMapCommand.My.MySettings
Get
Return Global.AWCArcMapCommand.My.MySettings.Default
End Get
End Property
End Module
End Namespace
 
B

blekros

Hi Brad,

When a DLl is sed by an application, it is running under the application's
context, and it is the application's configuration file that will be used.
Just add the necessary settings to the application's configuration file and
the DLL will use them.

--

I was quite sure that this behavior was changed with .NET 2.0, and the
default behavior of VS2005 seems to agree when you add an application
configuration file to a .dll class library project. Alas, confusion
reigns again.

I suppose I could customize my installer class to locate the
application.exe configuration and append my stuff to it somehow. I'll
think on that...

But the application configuration file (.exe.config) will be
problematic as it's a commercial app, subject to reinstalls for
version upgrades. It looks like I may have to go back to the
homegrown XML config file I started with in 1.1. Of course, then I
have to manually edit my web-reference source code to look it up,
instead of just setting the "dynamic" property.

So close, yet so far.


Brad


HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:http://www.miradyne.net


Using VS2005, VB.NET and .NET 2.0 Framework, I have a built a
mylib.dll class library. It is registered for COM interop. I have an
associated app.config. I build mylib project and get mylib.dll,
mylib.tlb, and mylib.dll.config. So far, so good.
I change the value of my setting in mylib.dll.config, using notepad.
I run a container app, which loads the COM wrapper, which should load
the .dll.config file and initialize my settings instance from
the .ddl.config file at SOME time. When is this time?
When I use a method in the library, I expect it to load my manually-
edited application setting, but instead, the value is what the code
was compiled with. Specifically, the default value specified in the
attribute on the settings.designer.vb for the property I'm using.
Here is the entirety of the generated class, settings.vb:
Namespace My
'This class allows you to handle specific events on the settings
class:
' The SettingChanging event is raised before a setting's value is
changed.
' The PropertyChanged event is raised after a setting's value is
changed.
' The SettingsLoaded event is raised after the setting values are
loaded.
' The SettingsSaving event is raised before the setting values are
saved.
Partial Friend NotInheritable Class MySettings
End Class
End Namespace
Where is a load /deserialization method for the .dll.config? Where is
the other part of the partial class?
Below is the entirety of settings.designer.vb. Where is the load /
deserialization taking place?
Am I supposed to implement the SettingsLoaded event and read it from
the .dll.config XML myself?
This appears to be a singleton object instantiated with a "new"
statement. There is no constructor that loads any file that is
obvious.
I've been waiting for this feature for a few years and would love to
use it. But, I don't see how it works. I don't see how it CAN work.
And, in fact, it is observed NOT TO WORK! {weeping, teeth gnashing}
What have a missed? It has to be something simple and obvious.
Thanks in advance,

'------------------------------------------------------------------------------
' <auto-generated>
' This code was generated by a tool.
' Runtime Version:2.0.50727.832
'
' Changes to this file may cause incorrect behavior and will be
lost if
' the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------
Option Strict On
Option Explicit On
Namespace My

Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator",
"8.0.0.0"), _
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
_
Partial Friend NotInheritable Class MySettings
Inherits Global.System.Configuration.ApplicationSettingsBase
Private Shared defaultInstance As MySettings =
CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New
MySettings),MySettings)
#Region "My.Settings Auto-Save Functionality"
#If _MyType = "WindowsForms" Then
Private Shared addedHandler As Boolean
Private Shared addedHandlerLockObject As New Object
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
_
Private Shared Sub AutoSaveSettings(ByVal sender As
Global.System.Object, ByVal e As Global.System.EventArgs)
If My.Application.SaveMySettingsOnExit Then
My.Settings.Save()
End If
End Sub
#End If
#End Region
Public Shared ReadOnly Property [Default]() As MySettings
Get
#If _MyType = "WindowsForms" Then
If Not addedHandler Then
SyncLock addedHandlerLockObject
If Not addedHandler Then
AddHandler My.Application.Shutdown,
AddressOf AutoSaveSettings
addedHandler = True
End If
End SyncLock
End If
#End If
Return defaultInstance
End Get
End Property
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _

Global.System.Configuration.DefaultSettingValueAttribute("http://
webservicehostname/virtualdirectory/LookupService.asmx")> _
Public ReadOnly Property
AWCDisplayDocumentCmd_remoteDocMgr_DBGateway() As String
Get
Return
CType(Me("AWCDisplayDocumentCmd_remoteDocMgr_DBGateway"),String)
End Get
End Property
End Class
End Namespace
Namespace My
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()>
_
Friend Module MySettingsProperty
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")>
_
Friend ReadOnly Property Settings() As
Global.AWCArcMapCommand.My.MySettings
Get
Return Global.AWCArcMapCommand.My.MySettings.Default
End Get
End Property
End Module
End Namespace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top