Author Topic: Best Approaches  (Read 13644 times)

0 Members and 1 Guest are viewing this topic.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Best Approaches
« Reply #15 on: July 10, 2006, 06:16:10 AM »
Doh!, I've even had this happen to me :oops:
I knew what it was as I wasn't looking for another issue (serialisation in your case), all though you build your dll with other modules they must also be in the same folder at runtime as your loaded dll.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Best Approaches
« Reply #16 on: July 10, 2006, 08:33:40 PM »
How did you go, did you get it sorted?
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

DBARANAS

  • Guest
Re: Best Approaches
« Reply #17 on: July 11, 2006, 05:26:11 AM »
I got a little farther. I went to a modeless form and had to add the doclock code becuse it started to throw and exception by going modeless

Dim doclock As DocumentLock = Application.DocumentManager.MdiActiveDocument.LockDocument()
'stuff
doclock.Dispose()

I have been trying to get deserialization working but everthying I try won't work. I checked your MSDN link but no luck that way.

I read this link. It explains some things

http://www.marcclifton.com/Articles/Performance/RawSerializer/tabid/130/Default.aspx

but it won't work with structures.

I just tried your suggestion about copying the modules in the bin/debug dir but it didn't work....Is that what you meant? It seems strange to have to do that

I think the problem has something to do with the version info and maybe if I can force it not to add it to the binary file it will work.

Funny that it seems to expect and knows the correct version but it just can't load it. Been googling since yesterday on "deserialization problem dll" Seems like lot's of people have this problem


DBARANAS

  • Guest
Re: Best Approaches
« Reply #18 on: July 11, 2006, 05:58:08 AM »
I just tried loading acad normally and running the dll outside of VS and it worked.

It think it has something to do with launching acad from VS.

Glenn R

  • Guest
Re: Best Approaches
« Reply #19 on: July 11, 2006, 06:06:58 AM »
I've done this before - you should be able to serialise to binary from a dll.

I've also found strange things that disappeared when you launch AutoCAD manually, not in the debugger...go figure.

Cheers,
Glenn.

MickD

  • King Gator
  • Posts: 3619
  • (x-in)->[process]->(y-out) ... simples!
Re: Best Approaches
« Reply #20 on: July 11, 2006, 06:58:41 AM »
Glad to hear you got it working.


I just tried your suggestion about copying the modules in the bin/debug dir but it didn't work....Is that what you meant? It seems strange to have to do that


Yes that's what I meant, the reason you have to load the other dll's that contain your other structures or code is no different to using any other dll, they must be in the same path of your dll or the windows system folder (or part of the global assembly files or similar for .net).
While they call them a 'class library', they are really both the lib and the dll in .net whereas in C++ you would link with .lib files when compiling your code but at runtime using the resources from the dll proper. You can do this because of 'jit' ing, your code is compiled into binary against your class lib just before use.
"Short cuts make long delays,' argued Pippin.”
J.R.R. Tolkien

DBARANAS

  • Guest
Re: Best Approaches
« Reply #21 on: July 11, 2006, 07:42:32 AM »
Yes I just got it working in the debugger too

This is strange. In desparation I substituted my structure with this simple little test and it worked

   Dim BinFormatter As New Binary.BinaryFormatter()
   Dim R As New Rectangle(10, 20, 100, 200)
   BinFormatter.Serialize(FS, R)

   Dim R As New Rectangle()
   R = CType(BinFormatter.Deserialize(FS), Rectangle)

Then I am on to something, I put my biggest structure in and it works. Put back the original structure and it works. I have absolutely no files copied anywhere else now. I reload VS still works.

I copied the project to another hardrive....stil works. I hope it is not some flaky thing in VS....

DBARANAS

  • Guest
Re: Best Approaches
« Reply #22 on: July 11, 2006, 11:41:32 AM »

[/quote]

Yes that's what I meant, the reason you have to load the other dll's that contain your other structures or code is no different to using any other dll, they must be in the same path of your dll or the windows system folder (or part of the global assembly files or similar for .net).
While they call them a 'class library', they are really both the lib and the dll in .net whereas in C++ you would link with .lib files when compiling your code but at runtime using the resources from the dll proper. You can do this because of 'jit' ing, your code is compiled into binary against your class lib just before use.
[/quote]

This is driving me crazy

I have 6 subs that read and write structures. I have 1 module where I keep all the structures. There is just 1 dll for the project.

By only stripping out the XML parts and replacing it with Binary nothing should have been any different. But it broke again the same way.

    Public Sub dataSetup(ByVal store As Boolean)

        'Select Case store
        '    Case True
        '        Dim SR As New StreamWriter("f:\data\setup.xml")
        '        Dim xmlSerial As New Xml.Serialization.XmlSerializer(opt.GetType)
        '        xmlSerial.Serialize(SR, opt)
        '        SR.Close()
        '        SR = Nothing
        '        xmlSerial = Nothing
        '    Case False
        '        Dim xmlSerial As New Xml.Serialization.XmlSerializer(opt.GetType)
        '        Dim SR As New StreamReader("f:\data\setup.xml")
        '        opt = DirectCast(xmlSerial.Deserialize(SR), setupOptions)
        '        SR.Close()
        '        SR = Nothing
        '        xmlSerial = Nothing
        'End Select

        Select Case store
            Case True

                Dim bf As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
                Dim fs As New IO.FileStream("f:\data\setup.dat", IO.FileMode.Create)
                bf.Serialize(fs, opt)
                fs.Close()
                fs = Nothing
                bf = Nothing

            Case False

                Dim bf As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
                Dim fs As New IO.FileStream("f:\data\setup.dat", IO.FileMode.Open)
                opt = DirectCast(bf.Deserialize(fs), setupOptions)
                fs.Close()
                fs = Nothing
                bf = Nothing

        End Select

I had a few subs doing it the binary way and everything worked then I went ahead and just changed them all and it broke. I went back and changed them one at a time and it worked until I changed the last one. If the first thing that happens it that an XML file gets serialized and then deserialized the all the binary read and writes will be OK after that.

Now it works again but only if I do this. If I don't do this then I get the JIT error and it cannot load the assembly. At least I now know what breaks it and what fixes it. What a hack job this is becoming  :pissed:


    End Sub

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Best Approaches
« Reply #23 on: July 11, 2006, 12:38:21 PM »
I'm out of my league here but . . .
Could this have anything to do with the "Copy Local" settings of the acdbmgd.dll and acmgd.dll?
I think they should be set to False when running in IDE and True when building for running outside IDE.

I know this frustrated me when I began to look at C#-AutoCAD.
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

Glenn R

  • Guest
Re: Best Approaches
« Reply #24 on: July 11, 2006, 06:28:31 PM »
OK, I'll need some more info before I can help.

What is the format of the file you are trying to serialize...is it pure XML or some other structure...is it a class object or what?
Can you post up the file format or attach an example file for me to see/test with?

Glenn R

  • Guest
Re: Best Approaches
« Reply #25 on: July 11, 2006, 06:49:28 PM »
Also, is there any particular design decision that made you use structures instead of classes or was it a case of a struct is the closest thing to a UDT that you were previously using?

Cheers,
Glenn.

DBARANAS

  • Guest
Re: Best Approaches
« Reply #26 on: July 11, 2006, 07:16:03 PM »
I'm out of my league here but . . .
Could this have anything to do with the "Copy Local" settings of the acdbmgd.dll and acmgd.dll?
I think they should be set to False when running in IDE and True when building for running outside IDE.

I know this frustrated me when I began to look at C#-AutoCAD.


I had these set to true, I switched them and tried it but it made no difference in this case

DBARANAS

  • Guest
Re: Best Approaches
« Reply #27 on: July 11, 2006, 08:30:51 PM »
OK, I'll need some more info before I can help.

What is the format of the file you are trying to serialize...is it pure XML or some other structure...is it a class object or what?
Can you post up the file format or attach an example file for me to see/test with?

These are all structures made up of primitives, some of the elements are array's and a few are multidimensional array's.

I made a stripped down version just to test this problem. I ran it a few times and it reproduces the problem exactly. it should run in c:\test

All you have to do is comment out the dataGrid subs which I left as the XML read write and the rest won't work. Put them back and it will work

I stripped out acdbmgd.dll and acmgd.dll to get the zip sile under 100K. Once you point the new paths it should work OK

DBARANAS

  • Guest
Re: Best Approaches
« Reply #28 on: July 11, 2006, 09:01:56 PM »
Also, is there any particular design decision that made you use structures instead of classes or was it a case of a struct is the closest thing to a UDT that you were previously using?

Cheers,
Glenn.

Yes structures were the closest thing to UDT's. I tried to use classes so I could not be limited by the amount of solid objects a model could contain but it was too hard for me so I am sticking with what already works.

I think of these structures like big cubes where one element can see something it is connected to and also know what the other element sees. There is lots of code that looks like this everywhere. After some time it started to make sense and became intuitive :lol:

                    .ang = (pr(.jP(mS)).ang + pr(.jP(mS)).angB) - 90
                    opsAstdW = fTangent(.angA, .stdW)
                    'Joined wall
                    ofsXIn(ref, pr(.jP(mS)).x, pr(.jP(mS)).y, pr(.jP(mS)).ang, pr(.jP(mS)).adjL + aAngOfs)

                    'this wall
                    ofsXIn(ref, .x, .y, pr(.jP(mS)).ang + pr(.jP(mS)).angB, .stdW)
                    ofsYOut(ref, .x, .y, pr(.jP(mS)).ang + pr(.jP(mS)).angB, opsAstdW + pr(.jP(mS)).oMatT(0))

I learned that the whole buiding structure is basically 1 big object because changing one design element affects so many things in related (building) assemblies. The #1 design rule for this project was "no drafting" everything is parametric and is done and undone entirely in the program.

I have done some off the wall things like let the user design the building and then based of the weekly price of lumber, the size of the trucks, the onsite assembly order.....it will figure out the actual sizes of wall panels.

And to top that as if it were not already enough...this site crews assemble the building like 1,2,3,4,5,.....which has nothing to do with the real references that are only internal to the program. Hard to believe but I have seen that get messed up, and like with any new construction system ...no matter how well you think you have thought of everything all it takes is for something like this to happen and it goes bad.