Community
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<ahmed.felix> wrote in messageI'm
href="news:6082835@discussion.autodesk.com">news:6082835@discussion.autodesk.com...
having trouble with making configuration sections in the app.config file to
work with Autocad. If I change the project output type to a windows
application and have a button call some code, the section handler works just
fine and returns the expected object, but apparently calling that same code
from within an Autocad command in a class library dll doesn't work, it returns
nothing. Any ideas on why this is happening? Does Autocad blocks the use of
the System.Configuration assembly somehow? I found this other post from
several years ago:
http://discussion.autodesk.com/forums/thread.jspa?messageID=5128820? in which
the guy apparently has the same problem and wasn't solved. Hopefully I'll have
better luck having passed more than 3 years from that. Thank
you.
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
"ahmed.felix" wrote in messageI'm
href="news:6082835@discussion.autodesk.com">news:6082835@discussion.autodesk.com...
having trouble with making configuration sections in the app.config file to
work with Autocad. If I change the project output type to a windows
application and have a button call some code, the section handler works just
fine and returns the expected object, but apparently calling that same code
from within an Autocad command in a class library dll doesn't work, it returns
nothing. Any ideas on why this is happening? Does Autocad blocks the use of
the System.Configuration assembly somehow? I found this other post from
several years ago:
http://discussion.autodesk.com/forums/thread.jspa?messageID=5128820? in which
the guy apparently has the same problem and wasn't solved. Hopefully I'll have
better luck having passed more than 3 years from that. Thank
you.
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<ahmed.felix> wrote in messageMy
href="news:6083310@discussion.autodesk.com">news:6083310@discussion.autodesk.com...
configuration file looks like the one in the attachment (I can't post xml
here, it doesn't show). This gets deserialized by the function
XmlSerializerSectionHandler
(http://www.codinghorror.com/blog/archives/000161.html), which returns the
object defined by this class:
---------------------------------------------------------- Public Class
MyStuff Dim dblFoo As Double Public Property Foo() As Integer Get Return
dblFoo End Get Set(ByVal value As Integer) dblFoo = value End Set End Property
Dim intValues As Collection(Of Integer) Public Property Values() As
Collection(Of Integer) Get Return intValues End Get Set(ByVal value As
Collection(Of Integer)) intValues = value End Set End Property End Class
--------------------------------------------------------------------- Now, I
just use this code:
--------------------------------------------------------------------- Dim
myObject As MyObject myObject = ConfigurationManager.GetSection("MyObject")
---------------------------------------- Now, this code works just fine when
run from a windows application, but running it from a dll loaded into Autocad
returns nothing. As far as I'm understanding from Norman Yuan post, there's no
way to make this work from inside Autocad other than pretty much rewrite part
of the System.Configuration to work from a custom xml file? I thought it might
be because of being a dll and acad.exe being the application as you just said,
but it seemed a little bit odd since app.config can be used inside a data
access layer which is a dll used by another program, can't it? The main
application can reference a dll, and that dll has its own configuration file
in which to store database information and such.
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<ahmed.felix> wrote in messageActually,
href="news:6083389@discussion.autodesk.com">news:6083389@discussion.autodesk.com...
thinking about it, if I use the deserialization approach there's no real need
to use the acad.exe.config file, using any xml file and passing the node as
parameter will return the object, only thing to do is parse the nodes.
Pointing the file path to the application name + .config even allows for the
use of the app.config file of the dll during development time. Making it work
as transparently as a normal configuration file should be easy with just a few
functions.