MDAC 2.7 Breaks .NET COM Interop with AutoCAD?

MDAC 2.7 Breaks .NET COM Interop with AutoCAD?

Anonymous
Not applicable
705 Views
10 Replies
Message 1 of 11

MDAC 2.7 Breaks .NET COM Interop with AutoCAD?

Anonymous
Not applicable
I just installed MDAC 2.7 on a workstation with a C# application that uses
Data.OleDb namespace in ADO.NET. I did this, of course, because I got the
error message saying that I need MDAC version 2.6 or higher if I want to use
the Data namespace. Oddly enough, the required MDAC version does not come
with the .NET Framework. The workstation is Windows 2000, so it only had
version 2.5 on it. Microsoft says they recommend 2.7, so I installed 2.7
(talk about blind faith).

Now, this application doesn't want to connect to AutoCAD anymore. My method
of connection worked flawlessly before, but now it suddenly doesn't. I was
able to duplicate the problem on another very similar workstation.
And--stupid me--I decided to try installing MDAC 2.7 on my development
computer (which I found out later already has 2.7 on it because it is
installed with VS.NET). To add insult to injury, this workstation was
already working with ADO.NET and AutoCAD Interop... so I should have left it
alone. Now even it doesn't want to connect to AutoCAD, even from within the
VS.NET IDE. I've tried rolling back on my dev workstation, but that doesn't
help. I also tried just installing 2.6 instead of 2.7, but there is no
difference. I will try rolling back on the other workstations to see if
that helps, but in the end, I still need 2.6 or higher to run the database
stuff so I need to find a way to get 2.6 or higher working.

So I am basically stuck. I can't seem to find anything (mainly using
Google) about this, so I need help! The code to connect to AutoCAD is
pretty straight-forward and is as follows:

private AcadApplication GetAcadA()
{
try
{
AcadApplication app =
(AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
return app;
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
return null;
}
}

This used to work fine, but now I get a "Specified cast is not valid" when
running through the Marshal.GetActiveObject line. I've tried a few
different ways of getting AutoCAD, like saving it to an object field and
then casting it to app using "as" instead of (...), but nothing I've tried
works. I'm out of ideas.

Anyone have any hints?
0 Likes
706 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
Eric Olson had this to say
:
> Anyone have any hints?

WinXP ships with MDAC 2.7 and I have no problems with COM Interop
including AutoCAD. Have you tried repairing the registry?

--
There are 10 kinds of people:
Those who understand binary and those who don't
http://www.acadx.com
0 Likes
Message 3 of 11

Anonymous
Not applicable
try this:

private AutoCAD.AcadApplication GetAcadA()
{
try
{
AutoCAD.AcadApplicationClass app = new AutoCAD.AcadApplicationClass();
return app;
}
catch (Exception e)
{etc.....}
}

Note: this will start acad.exe, but not show it. To make it visible, set the visible property:
app.visible = true;

As far as your data access components go, I've never run across the problem you're having. I'm using MDAC 2.7 and ADO.NET without any hassles. Do you have specific code that isn't working for you?

- Good luck, Craig Haroldson
0 Likes
Message 4 of 11

Anonymous
Not applicable
Nevermind that last question. I understand the problem now. Let me know if that first fix doesn't work for you.
0 Likes
Message 5 of 11

Anonymous
Not applicable
No I haven't tried that yet, but find it strange that it has a problem on
two machines already. It seems unlikely that a damaged registry would be
the cause, but I will check it to be sure.

With MDAC 2.5 on a Windows 2000 workstation, AutoCAD Interop worked and
database stuff didn't. I installed version 2.6 on this workstation, AutoCAD
Interop stopped working. I rolled back to 2.5 and did the dll cache flush
and it still didn't work. Installed 2.7, Interop still didn't work.

I'd try it again on another workstation (besides the two I already broke),
but I hate to break another one.

"Frank Oquendo" wrote in message
> WinXP ships with MDAC 2.7 and I have no problems with COM Interop
> including AutoCAD. Have you tried repairing the registry?
0 Likes
Message 6 of 11

Anonymous
Not applicable
eric,

i'm running win2000 and mdac2.7 (+sql-server2000) and have no problems at all
connecting or starting autocad. i did that also at workstations running winnt4
and installing mdac2.7 afterwards.
but what may help you is an experience i had with my way of handling versions.
i previously copied the development-directory and gave the new directory a new
name including the release-number. as paths (to modules) are stored relative it
should work, but in some cases (i don't know when) all interop-files where
rebuild from net and so not the actual versions.

maybe it helps, - alfred -

In article ,
edo@rahco.com says...
> I just installed MDAC 2.7 on a workstation with a C# application that uses
> Data.OleDb namespace in ADO.NET. I did this, of course, because I got the
> error message saying that I need MDAC version 2.6 or higher if I want to use
> the Data namespace. Oddly enough, the required MDAC version does not come
> with the .NET Framework. The workstation is Windows 2000, so it only had
> version 2.5 on it. Microsoft says they recommend 2.7, so I installed 2.7
> (talk about blind faith).
>
> Now, this application doesn't want to connect to AutoCAD anymore. My method
> of connection worked flawlessly before, but now it suddenly doesn't. I was
> able to duplicate the problem on another very similar workstation.
> And--stupid me--I decided to try installing MDAC 2.7 on my development
> computer (which I found out later already has 2.7 on it because it is
> installed with VS.NET). To add insult to injury, this workstation was
> already working with ADO.NET and AutoCAD Interop... so I should have left it
> alone. Now even it doesn't want to connect to AutoCAD, even from within the
> VS.NET IDE. I've tried rolling back on my dev workstation, but that doesn't
> help. I also tried just installing 2.6 instead of 2.7, but there is no
> difference. I will try rolling back on the other workstations to see if
> that helps, but in the end, I still need 2.6 or higher to run the database
> stuff so I need to find a way to get 2.6 or higher working.
>
> So I am basically stuck. I can't seem to find anything (mainly using
> Google) about this, so I need help! The code to connect to AutoCAD is
> pretty straight-forward and is as follows:
>
> private AcadApplication GetAcadA()
> {
> try
> {
> AcadApplication app =
> (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
> return app;
> }
> catch (Exception e)
> {
> System.Diagnostics.Debug.WriteLine(e.Message);
> return null;
> }
> }
0 Likes
Message 7 of 11

Anonymous
Not applicable
If you have to have data access and you have to use ADO.NET (versus ADO via COM Interop), you have to have MDAC 2.7 installed. So if that's the case, I'd start there, putting 2.7 back on.

Then, try removing all references to your autocad type libraries and also your System.Data reference. Re-add them and rebuild.

Also (reaching for anything here) if you're referencing a another class library you created in .NET, try referencing it as a project rather than a .dll. Sometimes the debugger will throw strange exceptions (as your invalid cast) simply because it wasn't caught (and re-thrown) in another class. That *could* be one explanation for the invalid cast you're seeing.
0 Likes
Message 8 of 11

Anonymous
Not applicable
I have reinstalled 2.7 on all workstations, but it doesn't make any
difference.

Also I tried what you recommend about removing the references, adding them
back, and then rebuilding(sounded like a good idea). That didn't change
anything either.

On your last suggestion, it got me thinking. I don't have any custom .NET
classes, but I do have my modified Interop.AutoCAD.dll wrapper. So, I
thought I should see what happens if I let .NET rebuild that wrapper again
by simply referencing the AutoCAD COM type library (who cares if events
don't sink at this point). When I did that, I got an error which I didn't
get before!

"A reference to 'AutoCAD 2000 Type Library' could not be added. Could not
create the wrapper assembly for the ActiveX type library 'C:\Program
Files\Acadm 6\ACAD.TLB'. You may need to register it."

I am going to try and reinstall AutoCAD (probably should have tried this a
long time ago). I will let you all know if that does anything. I find it
disturbing if I need to reinstall AutoCAD (and all SPs) after installing
MDAC 2.7 (especially after installing the .NET framework and support pack)
on all these workstations that I have to eventually roll this application
out to. What is more disturbing is that I seem to be the only person with
this problem here... The fact that I duplicated it on two workstations is
even more so.

Anyway, thanks for all your help thus far!

PS. Could someone explain or give linkage to this using ADO through COM
Interop thing? I'm not familiar with it. I'd like to use that if it means
not messing with MDAC versions.


"kidcoach" wrote in message
news:f12b62c.5@WebX.maYIadrTaRb...
If you have to have data access and you have to use ADO.NET (versus ADO via
COM Interop), you have to have MDAC 2.7 installed. So if that's the case,
I'd start there, putting 2.7 back on.
Then, try removing all references to your autocad type libraries and also
your System.Data reference. Re-add them and rebuild.
Also (reaching for anything here) if you're referencing a another class
library you created in .NET, try referencing it as a project rather than a
.dll. Sometimes the debugger will throw strange exceptions (as your invalid
cast) simply because it wasn't caught (and re-thrown) in another class. That
*could* be one explanation for the invalid cast you're seeing.
0 Likes
Message 9 of 11

Anonymous
Not applicable
eric,

hoping that this comes before reinstalling. to register acad.tlb you could for
example start excel, goto vba-editor and add acad.tlb to the references, that
should be enough to register it.

using ado through com instead of ado.net is no good idea as it reduces the
abilities and every dataaccess is sent to a round-trip through drivers. as far
as you have only a few records that will only reduce the speed at
databaseconnection, but running a query with >1000 records into a recordset
(ado) is extremly slower than ado.net (and you can disconnect from database
while working with "offline"-data).

- alfred -

In article <38C5CCF3A7E8688C4B38470366088AB8@in.WebX.maYIadrTaRb>,
edo@rahco.com says...
> I have reinstalled 2.7 on all workstations, but it doesn't make any
> difference.
>
> Also I tried what you recommend about removing the references, adding them
> back, and then rebuilding(sounded like a good idea). That didn't change
> anything either.
>
> On your last suggestion, it got me thinking. I don't have any custom .NET
> classes, but I do have my modified Interop.AutoCAD.dll wrapper. So, I
> thought I should see what happens if I let .NET rebuild that wrapper again
> by simply referencing the AutoCAD COM type library (who cares if events
> don't sink at this point). When I did that, I got an error which I didn't
> get before!
>
> "A reference to 'AutoCAD 2000 Type Library' could not be added. Could not
> create the wrapper assembly for the ActiveX type library 'C:\Program
> Files\Acadm 6\ACAD.TLB'. You may need to register it."
>
> I am going to try and reinstall AutoCAD (probably should have tried this a
> long time ago). I will let you all know if that does anything. I find it
> disturbing if I need to reinstall AutoCAD (and all SPs) after installing
> MDAC 2.7 (especially after installing the .NET framework and support pack)
> on all these workstations that I have to eventually roll this application
> out to. What is more disturbing is that I seem to be the only person with
> this problem here... The fact that I duplicated it on two workstations is
> even more so.
>
> Anyway, thanks for all your help thus far!
>
> PS. Could someone explain or give linkage to this using ADO through COM
> Interop thing? I'm not familiar with it. I'd like to use that if it means
> not messing with MDAC versions.
>
>
> "kidcoach" wrote in message
> news:f12b62c.5@WebX.maYIadrTaRb...
> If you have to have data access and you have to use ADO.NET (versus ADO via
> COM Interop), you have to have MDAC 2.7 installed. So if that's the case,
> I'd start there, putting 2.7 back on.
> Then, try removing all references to your autocad type libraries and also
0 Likes
Message 10 of 11

Anonymous
Not applicable
Well, not sure if I feel like an idiot or what, but reinstalling the AutoCAD
service packs 3 and 4 did the trick. I am pretty sure that I installed them
already, but SP3 doesn't let you install if it's already been done, so
apparently it needed to be done. Now it works.

As far as the other workstation, I know for sure that I installed the
service packs, but it stopped working too after installing MDAC 2.7. So I
will try REINSTALLING the service packs on that one to see what happens. If
it doesn't let me install the SPs then I will just reinstall AutoCAD again.

At any rate it looks like MDAC messed up my AutoCAD. Good to at least have
a lead.

But (edited), does this .NET stuff require a lot of work. Hope this trouble and
learning pays off!

Thanks again for the help!

"Eric Olson" wrote in message
news:38C5CCF3A7E8688C4B38470366088AB8@in.WebX.maYIadrTaRb...
> I have reinstalled 2.7 on all workstations, but it doesn't make any
> difference.
>
> Also I tried what you recommend about removing the references, adding them
> back, and then rebuilding(sounded like a good idea). That didn't change
> anything either.
>
> On your last suggestion, it got me thinking. I don't have any custom .NET
> classes, but I do have my modified Interop.AutoCAD.dll wrapper. So, I
> thought I should see what happens if I let .NET rebuild that wrapper again
> by simply referencing the AutoCAD COM type library (who cares if events
> don't sink at this point). When I did that, I got an error which I didn't
> get before!
>
> "A reference to 'AutoCAD 2000 Type Library' could not be added. Could not
> create the wrapper assembly for the ActiveX type library 'C:\Program
> Files\Acadm 6\ACAD.TLB'. You may need to register it."
>
> I am going to try and reinstall AutoCAD (probably should have tried this a
> long time ago). I will let you all know if that does anything. I find it
> disturbing if I need to reinstall AutoCAD (and all SPs) after installing
> MDAC 2.7 (especially after installing the .NET framework and support pack)
> on all these workstations that I have to eventually roll this application
> out to. What is more disturbing is that I seem to be the only person with
> this problem here... The fact that I duplicated it on two workstations is
> even more so.
>
> Anyway, thanks for all your help thus far!
>
> PS. Could someone explain or give linkage to this using ADO through COM
> Interop thing? I'm not familiar with it. I'd like to use that if it
means
> not messing with MDAC versions.
>
>
> "kidcoach" wrote in message
> news:f12b62c.5@WebX.maYIadrTaRb...
> If you have to have data access and you have to use ADO.NET (versus ADO
via
> COM Interop), you have to have MDAC 2.7 installed. So if that's the case,
> I'd start there, putting 2.7 back on.
> Then, try removing all references to your autocad type libraries and also
> your System.Data reference. Re-add them and rebuild.
> Also (reaching for anything here) if you're referencing a another class
> library you created in .NET, try referencing it as a project rather than a
> .dll. Sometimes the debugger will throw strange exceptions (as your
invalid
> cast) simply because it wasn't caught (and re-thrown) in another class.
That
> *could* be one explanation for the invalid cast you're seeing.
>
>
0 Likes
Message 11 of 11

Anonymous
Not applicable
Alfred, I will try this on the other workstation with the problem. Thanks
for the idea.

That sounds a bit like what I guessed about using ADO through COM Interop.
Interop is a dirty word, in my book... Necessary sometimes, but still dirty.

Thanks!

"Alfred NESWADBA" wrote in message
news:MPG.18605caa3488427b9896e0@discussion.autodesk.com...
> eric,
>
> hoping that this comes before reinstalling. to register acad.tlb you could
for
> example start excel, goto vba-editor and add acad.tlb to the references,
that
> should be enough to register it.
>
> using ado through com instead of ado.net is no good idea as it reduces the
> abilities and every dataaccess is sent to a round-trip through drivers. as
far
> as you have only a few records that will only reduce the speed at
> databaseconnection, but running a query with >1000 records into a
recordset
> (ado) is extremly slower than ado.net (and you can disconnect from
database
> while working with "offline"-data).
>
> - alfred -
>
> In article <38C5CCF3A7E8688C4B38470366088AB8@in.WebX.maYIadrTaRb>,
> edo@rahco.com says...
> > I have reinstalled 2.7 on all workstations, but it doesn't make any
> > difference.
> >
> > Also I tried what you recommend about removing the references, adding
them
> > back, and then rebuilding(sounded like a good idea). That didn't change
> > anything either.
> >
> > On your last suggestion, it got me thinking. I don't have any custom
.NET
> > classes, but I do have my modified Interop.AutoCAD.dll wrapper. So, I
> > thought I should see what happens if I let .NET rebuild that wrapper
again
> > by simply referencing the AutoCAD COM type library (who cares if events
> > don't sink at this point). When I did that, I got an error which I
didn't
> > get before!
> >
> > "A reference to 'AutoCAD 2000 Type Library' could not be added. Could
not
> > create the wrapper assembly for the ActiveX type library 'C:\Program
> > Files\Acadm 6\ACAD.TLB'. You may need to register it."
> >
> > I am going to try and reinstall AutoCAD (probably should have tried this
a
> > long time ago). I will let you all know if that does anything. I find
it
> > disturbing if I need to reinstall AutoCAD (and all SPs) after installing
> > MDAC 2.7 (especially after installing the .NET framework and support
pack)
> > on all these workstations that I have to eventually roll this
application
> > out to. What is more disturbing is that I seem to be the only person
with
> > this problem here... The fact that I duplicated it on two workstations
is
> > even more so.
> >
> > Anyway, thanks for all your help thus far!
> >
> > PS. Could someone explain or give linkage to this using ADO through COM
> > Interop thing? I'm not familiar with it. I'd like to use that if it
means
> > not messing with MDAC versions.
> >
> >
> > "kidcoach" wrote in message
> > news:f12b62c.5@WebX.maYIadrTaRb...
> > If you have to have data access and you have to use ADO.NET (versus ADO
via
> > COM Interop), you have to have MDAC 2.7 installed. So if that's the
case,
> > I'd start there, putting 2.7 back on.
> > Then, try removing all references to your autocad type libraries and
also
0 Likes