TheSwamp

Code Red => .NET => Topic started by: jmaeding on August 05, 2008, 01:11:52 PM

Title: db.ReadDwgFile not working in 2006
Post by: jmaeding on August 05, 2008, 01:11:52 PM
I did an app and tested on 2008, it could open just about any dwg and deal with it dbx style.
In 2006, its not working for any file.
I started a new project for testing with this code:
Code: [Select]
namespace ProgTestingAcad
{
    public class Program
    {
        [Autodesk.AutoCAD.Runtime.CommandMethod("QQQ")]
        static public void Test1()
        {
            try {
                using (AcDb.Database db = new AcDb.Database(false, true)) {
                    db.ReadDwgFile(@"F:\0001\Engineering\Base Files\1E-OA_Project-CALC.dwg", System.IO.FileShare.Read, false, null);
                }
            }
            catch { }
        }
    }
}

Its catching every time.
the files I tested on are very generic, all created in acad 2006.
I have not programmed on 2006 in a while, was there a change in the .net API I forgot about?
thanks
Title: Re: db.ReadDwgFile not working in 2006
Post by: T.Willey on August 05, 2008, 01:29:22 PM
That is pretty much how I do it in '06.  The only thing different is I use true instead of false for the third argument.
Title: Re: db.ReadDwgFile not working in 2006
Post by: sinc on August 05, 2008, 01:42:36 PM
Maybe a reference problem...?  Are you linking to the right versions of the managed libraries?

Also, it sounds unlikely that this is the cause of your issue, but there seems to be a problem using the references in the installation directory, if you have multiple versions of Autocad installed on your development machine.  For example, if you have both Autocad 2007 and Autocad 2008 on your machine, and you reference the managed libraries in the Autocad 2007 install directory, your code will not run on any machine that has only Autocad 2007 installed on it.  However, if you link to the managed libraries in the ObjectARX 2007 SDK, everything is fine.  This issue still exists with the 2008 and 2009 releases.  I haven't tried doing anything with 2006, but I'm assuming you see the issue there, too.
Title: Re: db.ReadDwgFile not working in 2006
Post by: Glenn R on August 05, 2008, 02:48:16 PM
You haven't mentioned these:
.NET Framework version?
Visual Studio version?

Also, are you getting the errors whilst debugging, in Release or both?
Title: Re: db.ReadDwgFile not working in 2006
Post by: jmaeding on August 05, 2008, 03:53:10 PM
well, glad to hear its likely something I a doing wrong, that can be fixed.
I am targeting .net 2.0 framework, though I would like to use 3.5.
Can I use 3.5 without affecting acad?  Not sure if the acad dll's play ok if I do that.

Im using VS 2008.

I think I will try a truly fresh project, as the one I am using used to reference the acad 2008 dll's.
thx for the replies so far.
Title: Re: db.ReadDwgFile not working in 2006
Post by: Glenn R on August 05, 2008, 04:04:08 PM
Also, what is the error you're getting (you didn't post that) and:

Are you getting the error whilst debugging, Release or both?
Title: Re: db.ReadDwgFile not working in 2006
Post by: jmaeding on August 05, 2008, 04:11:12 PM
interesting, I just tried the release version and it worked!
This was on a fresh project from scratch.
So its the debug version that is not working, does that nail it down to a particular problem?
I still cannot get the debug version to not catch...
thanks
Title: Re: db.ReadDwgFile not working in 2006
Post by: Glenn R on August 05, 2008, 04:14:54 PM
You're still not posting the error btw....

Also, do you have 2.0 SP1 or 3.0 SP1 installed?
Title: Re: db.ReadDwgFile not working in 2006
Post by: jmaeding on August 05, 2008, 04:19:20 PM
forgot, I'm targeting framework 3.5 now and error message is (e.message..):
Attempted to read or write protected memory. This is often an indication that other memory is corrupt..."

but nothing is corrupt from any evidence I have seen.  I believe that message is a bit generic for a read failure.
Title: Re: db.ReadDwgFile not working in 2006
Post by: jmaeding on August 05, 2008, 04:21:35 PM
I am using framework 3.5 now, but for 2.0 I have sp1, 3.0 sp1.
Title: Re: db.ReadDwgFile not working in 2006
Post by: Glenn R on August 05, 2008, 04:31:00 PM
That's what I suspected. Looky here (http://www.theswamp.org/index.php?topic=24074.msg291125#msg291125).

From what I've seen on the adesk ng recently with ReadDwgFile and '06, the general consensus is that it is a SP issue. If you have access to 2007, you will probably find it works fine.

I can't offer a suggestion, because '06 was built (look in the acad.exe.config) with 1.1 in mind, even though it tries to use the latest framework version. You might be able to try to get it to target 2.0 for instance...but that's just a guess and not optimal IMO.

I'm fairly sure that I have run code against 2006 compiled from VS 2005 even with later frameworks and it worked, but I can't say that for sure....
Title: Re: db.ReadDwgFile not working in 2006
Post by: jmaeding on August 05, 2008, 04:43:38 PM
found a post by WSteed on the Adesk NG.
I believe that person is our San Diego office .net programmer!  Small world, I was about to ask him too...
the answer was this:

"...After much effort, I discovered that the problem had occurred when I updated the .NET 2.0 with SP1. The problem also occurs when installing the .NET 3.0 SP1 (which installs 2.0 SP1 also). Right now I have restored my machine to the pre SP1 state, ie. .NET 1.1, 1.1 Hotfix, 2.0 & 3.0, all the code works perfectly."

I would have NEVER EVER suspected this, thanks God for computers...which I guess caused the problem in the first place...oh well, I'll see if I have any luck with removing the sp's.
Title: Re: db.ReadDwgFile not working in 2006
Post by: jmaeding on August 05, 2008, 05:02:12 PM
I posted an ADN support request, lets see what Adesk has to say...
Title: Re: db.ReadDwgFile not working in 2006
Post by: Glenn R on August 05, 2008, 05:16:52 PM
Also, unless you are modifying the drg you are opening, I wouldn't use this:

FileShare.Read

But use this:

FileShare.ReadWrite (or whatever that enum value is).

Title: Re: db.ReadDwgFile not working in 2006
Post by: jmaeding on August 05, 2008, 06:01:37 PM
hmm, another unsuspected tidbit.  Maybe it should have been "ReadRight"!
Title: Re: db.ReadDwgFile not working in 2006
Post by: vegbruiser on August 06, 2008, 06:36:39 AM
It might be nothing (but then again it might not):

in the line that reads
Code: [Select]
db.ReadDwgFile(@"F:\0001\Engineering\Base Files\1E-OA_Project-CALC.dwg", System.IO.FileShare.Read, false, null);It seems to have an "@" symbol in front of the filename??? (or is it something that C# uses that VB doesn't?)
Title: Re: db.ReadDwgFile not working in 2006
Post by: Glenn R on August 06, 2008, 06:49:08 AM
The @ symbol is a 'verbatim string' - take it as it is and don't interpret any escape characters
Title: Re: db.ReadDwgFile not working in 2006
Post by: vegbruiser on August 06, 2008, 06:54:05 AM
The @ symbol is a 'verbatim string' - take it as it is and don't interpret any escape characters
Ah, thanks. I'll remember that for future reference. :)