TheSwamp

Code Red => .NET => Topic started by: Bill Tillman on October 01, 2012, 10:18:26 AM

Title: VS 2012 Express vs VB 2010 Express
Post by: Bill Tillman on October 01, 2012, 10:18:26 AM
Has anyone else noticed that you can put the exact same block of VB.NET code in VB 2010 Express and VS 2012 Express and VS 2012 Express will fail to run it.

Code: [Select]
Sub Main()
        Dim vAcadApp As AutoCAD.AcadApplication
        Dim vAcadDoc As AutoCAD.AcadDocument
        vAcadApp = New AutoCAD.AcadApplication
        vAcadApp.Visible = True
        vAcadApp.WindowState = AutoCAD.AcWindowState.acMax

End Sub

In VB 2010 Express, this will open my copy of AC 2013 with the main window maximized. In VS 2012 Express this will create:

Quote
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in ConsoleApplication3.exe

Additional information: Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))

and it's pointing to the Visible=True line. And if I comment out that line it will create the same error on the next line.  Guess I will have to downgrade back to VB 2010 Express.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: dgorsman on October 01, 2012, 10:20:56 AM
Stupid question time: have you made *all* the same tweaks to the 2012 install that you've made to the 2010 install over the years?
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: Bill Tillman on October 01, 2012, 10:34:30 AM
That's a good point...but AFAIK the VB 2010 Express copy I'm running is as-is, out of the box. I did not make any tweaks to it...not yet anyway. I would love to set the text editor's colors to the same as the default one in VS 2012 Express. That dark background with colored letters is not only easier on the eyes, but it looks really cool. Oh yes, I have not made any tweaks to VS 2012 Express either except setting that color for the text editor.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: BlackBox on October 01, 2012, 10:53:23 AM
Has anyone else noticed that you can put the exact same block of VB.NET code in VB 2010 Express and VS 2012 Express and VS 2012 Express will fail to run it.

When you 'put the exact same block of VB.NET code' into VS 2012 Express, are you opening the 2010 project, or pasting the block of code?

If the latter, are you compiling your new/different 2012 project to the same .NET framework (i.e., 4.0 for 2013)?

Also, since you've installed VS 2012 Express, you now have .NET 4.5 installed... Did you specify AutoCAD 2013's Acad.Exe.Config to use .NET 4.0 (as the newest is used by default, unless specified).

HTH
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: Bill Tillman on October 01, 2012, 02:21:01 PM
It's actually a VS 2012 project. And as I found out just now, you cannot open a VS 2012 Express project using VB 2010 Express. It reports that the project was built with a newer version. Ok so here is the scoop.

I created the project in VS 2012 Express VB.NET module. I then tried to run it but it stopped as described above. I then went to a remote session on the other monitor that I'm running on another computer. Both machines have AC 2013 with SP1.1 installed. The remote machine has VB 2010 Express and my local desktop has VS 2012 Express. On the remote machine I opened a new project and installed the exact same reference for AutoCAD 2013. Then I copied and pasted the code into the project. It ran just fine.

Now the OMG part. On this local desktop I also have VB 2010 Express installed so I tried the exact same setup with it and the program crashed at exactly the same spot. The difference between the machine that this will run on and one it will not...the remote machine where it runs is Windows XPx86 with SP3, this local desktop on which it will not run is Windows 7x64.

I hate to think that Win7 is the problem. I left a PM for you RenderMan on cadtutor describing how this exact code will not work at my home where I also run Win7. I have a laptop running Windows Vista and the code runs fine there too. Ooooh this is getting spooky. But again I'm deep in the debugging part and hope that I'm not being a flake and reporting bad information. AFAIK, what I'm seeing seems to be related to Windows 7. I will keep trying with this but the bosses are starting to lose patience.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: Bill Tillman on October 01, 2012, 03:06:09 PM
One of the developers who works in the IT dept came by and looked at it. He quickly became deer in the headlights. They are going to set me up with Virtual Machine XP to see if we can get to the bottom of this. I can't believe in this whole place they don't have even one spare computer to use as a test machine but that's where I'm at.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: BlackBox on October 01, 2012, 03:24:02 PM
I left a PM for you RenderMan

... Didn't mean to keep you waiting; work's crazy right now.

I will keep trying with this but the bosses are starting to lose patience.

FWIW -

Unless there's a requirement for .NET 4.5 framework that I am unaware of, skip the non-critical VS 2012 Express upgrade, and use VS 2010, given that your testing shows that it (the 2010 project) works.

Management doesn't care for non-essential upgrades, especially when that pushes back deadline(s).

** Edit - Helk; they don't like it when it's due to critical upgrades for that matter! :lol: LoL
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: Bill Tillman on October 01, 2012, 03:40:49 PM
Sorry dude, I forgot to include that fact. I have set VS 2012 Express to work with 4.0 FW. And that is the FW on the other machines as well. In spite of IT trying to set me up with VM...which could take days, I will do some extra cirricular work on this tonight at my home lab. I will have to build myself an XP machine because I've recently thrown out all the old computers which I had running XP. Heck, I don't even have a parallel port anymore because of all the new replacements I've bought. But I still have the license for about 4 or 5 XP installs. I will build an XP machine with both VB 2010 Express and VS 2012 Express. I will use the trial version of AutoCAD to do the testing even though we just cut a PO from this office today to buy another 2013 license from our reseller. At some point this evening I will know if it's a Windows 7 issue or not. I gotta believe there is something else happening but what I saw today was only limited when it was being run on Windows 7.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: BlackBox on October 01, 2012, 03:48:04 PM
Sorry dude, I forgot to include that fact. I have set VS 2012 Express to work with 4.0 FW. And that is the FW on the other machines as well.

No worries; but what about checking this (http://www.theswamp.org/index.php?topic=42898.msg481125#msg481125)? 
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: BlackBox on October 01, 2012, 03:52:05 PM
Copied from an older OOTB Acad.Exe.Config:

Code - C#: [Select]
  1. <!--<snip>-->
  2.  
  3.   <startup>
  4.     <!--We always use the latest version of the framework installed on the computer. If you
  5. are having problems then explicitly specify .NET 2.0 by uncommenting the following line.
  6.                 <supportedRuntime version="v2.0.50727"/>
  7. -->
  8.   </startup>
  9.  
  10. <!--<snip>-->
  11.  


... Not sure if 2013 still has this behavior or not.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: Bill Tillman on October 01, 2012, 04:22:46 PM
Thanks...again I still new to a lot of this. In setting the FW for the project should I be using the .NET Framework 4.0 or the .NET Framework 4.0 for Client. I just noticed that the default setting on the VB 2010 Express on the Win7 machine is Client, as is the VB 2010 Express copy of the XP machine.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: BlackBox on October 01, 2012, 04:28:11 PM
FWIW -

I am by _no_ means a .NET expert (still in my piper cub (http://www.theswamp.org/index.php?topic=42836.msg480526#msg480526) as it happens *Will Tony ever stop changing his avatar?*), but my apps are set to '.NET framework #.#" (no client).
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: Bill Tillman on October 01, 2012, 05:23:16 PM
It does appear to be something with Windows 7 and/or x64 bit CPU's.

http://msdn.microsoft.com/en-us/library/ms228772(v=vs.80).aspx (http://msdn.microsoft.com/en-us/library/ms228772(v=vs.80).aspx)

More to come as I debug this...unless someone would like to step in at this point with a resolution.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: BlackBox on October 01, 2012, 07:25:31 PM
I only skimmed tgat MSDN link... But, last I checked all versions of Autocad were single threaded (even 2013, despite core console), so multi-threading contention should not be an issue.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: Bill Tillman on October 02, 2012, 09:04:36 AM
That link at MSDN contains what appears to be a very complicated fix for this. And some extensive testing I did last night shows me that in spite of it's nice Window dressing, and that the automation I did with Excel worked bitchin fine, using the new VS 2012 Express, with AutoCAD at least, it is filled with land mines. And even though the supervisors here are all for it, I told them this morning we need to leave well enough alone. So I'm going back to VB 2010 Express and will stay with that platform for the forseeable future. What the heck, all that testing last night gave me something constructive to do while I watched the Cowboys self-destruct and embarass the entire NFL.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: dgorsman on October 02, 2012, 09:26:16 AM
Might want to throw some relevant details at Microsoft.  They might have a solution, or at least get the problem logged for the next SP.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: BlackBox on October 02, 2012, 10:04:51 AM
What the heck, all that testing last night gave me something constructive to do while I watched the Cowboys self-destruct and embarass the entire NFL.

 :-D
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: n.yuan on October 02, 2012, 10:25:38 AM
Just a blind shoot in the dark: I do not have access to AutoCAD2013.

I do not think it has anything to do with .NET version, nor VS version (2010 vs 2010), because you are doing a standalone exe to automate AutoCAD. The .NET version of your EXE app has nothing to do with AutoCAD. You can do your app with .NET2.0, 3.x, 4.0 or 4.5. And certainly you should not bother to change <startup.<supportedRuntime.../></startup> in acad.exe.config, just because you want to automate AutoCAD froom external app.

Yes, it is very likely the 32-bit and 64-bit issue, but not because of Win7, I'd guess.

One possible thing to look into:

Since Acad2013, I have heard, Autodesk stops install AutoCAD interop assemlies (PIA, which wrapps AutoCAD COM interfaces that you use for automation) into GAC. With pre-2013 AutoCAD, you added rerferences to AutoCAD COM, but VS does not generate Autodesk.AutoCAD.Interop.dll, beccause it already exists in the GAC. But with Acad2013, I guess, VS has to generate the interop assembly (with tlbimp.exe tool), or you make sure you set reference to the interop assebly from the downloaded ARX SDK and the assembly has to be either copy to local or to be embeded.

Since there are 2 sets of interop assemblies from the SDK for 32-bit and 64-bit AutoCAD, I not very sure which one you should use, but I'd try the 64-bit version one: although it doe not matter what your exe app builds against in term of CPU (Any/32/64) when it automate AutoCAD, but since it has to communicate with AutoCAD via the interop assemblies...thus, try the 64-bit interop assemblies first.

Again, since I do not have access to Acad2013, so, just some guesses that may be of a bit help.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: BlackBox on October 02, 2012, 10:37:03 AM
I do not think it has anything to do with .NET version, nor VS version (2010 vs 2010), because you are doing a standalone exe to automate AutoCAD. The .NET version of your EXE app has nothing to do with AutoCAD. You can do your app with .NET2.0, 3.x, 4.0 or 4.5. And certainly you should not bother to change <startup.<supportedRuntime.../></startup> in acad.exe.config, just because you want to automate AutoCAD froom external app.

Good catch... I completely overlooked the 'external' comment, and was still in my mindset for work, where everything (currently) is plug-in. :ugly: Oops.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: Bill Tillman on October 03, 2012, 07:58:23 AM
FWIW...I did some more testing with this issue last night and now I really believe they at least the IT Director here has his act together. His big push is to move us away from M$ and go to platform neutral processes. In his discussions with us he has said that half the applications we have here will not run on Windows 7 and now the market is pushing us to go to Windows 8 or worse, "Metro" computing...if they even call it that anymore.

What I found was that most of the .NET code I've been plaigerizing, er uh, that is developing, over the last 6 months will run fine on Windows XP 32 bit. Move that same code or exe over to Windows 7 and oops... will someone please hand me a towel so I can get the egg off my face. Case in point. I found a nice snippet on the FileSystemWatcher method Renderman pointed me to. It works great for my purposes and as long as I keep it on Windows XP 32 bit everything is fine. But move the same code over to Windows 7 and NOT. Now instead of being able to move on I have to find some way of adjusting for things like cross-thread errors and such. So much to learn and so little time....!
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: n.yuan on October 03, 2012, 09:51:31 AM
It is not WinXP vs Win7! It is 32-bit vs 64-bit. In this regard, be it is MS Windows, or other OS, just from 32-bit to 64-bit will break a lot of applications for sure. Especially when you do the AutoCAD automation from COM API and from extermal EXE.

BTW, even you use Win7 64-bit, it is AutoCAD to be blamed, not Windows: 32-bit apps would run happily in 64-bit Windows. It is AutoCAD being 64-bit that creates your problem. There is way to manage 32-bit AutoCAD being intalled in 64-bit Windows, which is not supported by Autodesk, of course. Then you would give up letting AutoCAD use more memory beyond 4G.

IMO, automating AutoCAD from external EXE app is hardly a good solution in most cases, if not all. Just think, when you do AutoCAD automation from EXE app, you still need AutoCAD being installed and running (or started by your EXE app before AutoCAD can be automated). Why just let user fire up AutoCAD and run whatever process inside AutoCAD? It is a lot faster, less confusing (user do not have to switch beteen app windows, not to mention user likely accidentally closes Acad or your app window - I experince a user who always close current window to swtich to another app!). If you build your AutoCAD application inside AutoCAD with Acad .NET API, the code is identical in 32-bit and 64-bit Window(XP/VIST/7).

Or you may want to do AutoCAD programming ONLY with AutoLISP (well, it only runs inside AutoCAD) in order to be "platform neutral", in regard of AutoCAD.
Title: Re: VS 2012 Express vs VB 2010 Express
Post by: BlackBox on October 03, 2012, 11:11:01 AM
FWIW Bill, as I know more about your situation from offline discussion, n.yuan makes an excellent argument for using plug-in in lieu of stand-alone EXE.

The plug-in, once AutoCAD is fired up and assembly loaded via registry, the FileSystemWatcher can still be initialized, and run (along with the rest of your application).

** Edit to add - You can also incorporate a startup script on your networked computer to launch a specific AutoCAD application icon (to set any necessary profile, etc. at open). Then, you need only restart the computer... AutoCAD is opened automagically, and stays open since it's not a user's machine. Your code takes care of opening, and closing Documents. Just saying.