.NET

Reply
Distinguished Contributor
jmaeding
Posts: 977
Registered: ‎12-27-2006
Message 1 of 8 (249 Views)

odd error when picturebox loads its image

249 Views, 7 Replies
10-24-2013 05:17 PM

on projects that reference acad 2013 assemblies, specifically accormgd, my pictureboxes throw an exception when loading their image:

this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));

 it says cannot find assembly accoremgd....

Don't know how the heck that involves a picture box, since all object types have full names here.

 

This Project is set to run as a windows application, for testing reasons. That is likely related, but I do this all the time with no issues. I can comment out the line above and no issues.

 

Is there some entanglement between pictureboxes and the acad assemblies?

 

 

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 8 (208 Views)

Re: odd error when picturebox loads its image

10-25-2013 10:15 AM in reply to: jmaeding

If you run your project as a standalone executable and it contains references to AutoCAD assemblies, the error will occur at the first attempt to compile a method that contains a reference to any type in one of the AutoCAD assemblies.

 

There's nothing 'odd' about it, you can't reference those assemblies in a standalone executable.  The precise cause could be anywhere, but in your case, it is most-likely because an AutoCAD type is reference from your compiler-generated resources class.

Distinguished Contributor
jmaeding
Posts: 977
Registered: ‎12-27-2006
Message 3 of 8 (199 Views)

Re: odd error when picturebox loads its image

10-25-2013 12:07 PM in reply to: jmaeding

I understand what you are getting at, but my experience has been that its not a problem at all to have acad assemblies referenced to a windows app. It may be that this is because nothing is using the acad assemblies in that mode, and they should not if I coded correctly.

 

Either way, why would the picturebox control be calling an acad assembly?

The objects are fully pathed, starting with system. There should be no confusion on that by VS.

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 4 of 8 (188 Views)

Re: odd error when picturebox loads its image

10-25-2013 04:24 PM in reply to: jmaeding

jmaeding wrote:

I understand what you are getting at, but my experience has been that its not a problem at all to have acad assemblies referenced to a windows app.


I tried to explain why the error occurs.  The error may not occur in some cases. For example, if your Windows executable does not try to execute methods that contain references to AutoCAD assemblies, then there will be no error. Otherwise, there will be an error, and that can also occur when you expose public properties on a class, whose type(s) are from an AutoCAD assembly.

 

I also mentioned that the problem is most-likely because the compiler-generated resources class contains a reference to one or more type(s) from an AutoCAD assembly. The referenced type(s) could be the type of public properties. The line of code you show, requires that compiler-generated resources class to be loaded and the method that returns the value to be compiled, which in-turn may trigger an attempt to load the AutoCAD assembly containing a type referenced from the resources class, which has nothing to do with the PictureBox.

 

Look at the compiler-generated resources class and see if there are any references to types from the AutoCAD assembly.

Distinguished Contributor
jmaeding
Posts: 977
Registered: ‎12-27-2006
Message 5 of 8 (185 Views)

Re: odd error when picturebox loads its image

10-25-2013 04:36 PM in reply to: DiningPhilosopher

when you say "compiler-generated resources class" what exactly do you mean?

I am guessing the .resx file VS made for the form.

That code is xml, and has no acad types in it.

 

I get that somewhere the acad assemblies are indeed being called, and that you have to look at the lineage of things, but the form with this control has no properties or anything involving acad types.

I have a different function in another class that makes an instance of the form and shows it.

 

Thx for your help on this, I can tell you know the details of .net better than I.

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 6 of 8 (134 Views)

Re: odd error when picturebox loads its image

10-29-2013 03:36 PM in reply to: jmaeding

jmaeding wrote:

when you say "compiler-generated resources class" what exactly do you mean?

I am guessing the .resx file VS made for the form.

That code is xml, and has no acad types in it.

 


resources.GetObject("pictureBox2.Image")

The resources class is not XML or in a resx file.  It's generated by the compiler from the resx file.

 

Use the IDE's 'go to the definition' function to go to the declaration of the resources object, and then to the definition of the type of the object, and you'll find it.

Distinguished Contributor
jmaeding
Posts: 977
Registered: ‎12-27-2006
Message 7 of 8 (129 Views)

Re: odd error when picturebox loads its image

10-29-2013 03:43 PM in reply to: DiningPhilosopher

its all  system stuff though, these are built in controls.

I cleaned things out and added back, so code is now: (does not help though)

this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));

 I'm not sure why loking at the object definition for any of this would help, but maybe you mean I should do that to verify its behaving.

I use object broswer all the time, just did not know that's what you meant.

ADN Support Specialist
Balaji_Ram
Posts: 701
Registered: ‎03-21-2011
Message 8 of 8 (98 Views)

Re: odd error when picturebox loads its image

11-07-2013 09:13 PM in reply to: jmaeding

Hi James,

 

Sorry for the delay.

 

Can you provide a sample project for me to try and reproduce the error message ?

 

Thanks.



Balaji
Developer Technical Services
Autodesk Developer Network

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.