.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

odd error when picturebox loads its image

7 REPLIES 7
Reply
Message 1 of 8
JamesMaeding
512 Views, 7 Replies

odd error when picturebox loads its image

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?

 

 


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

7 REPLIES 7
Message 2 of 8

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.

Message 3 of 8
JamesMaeding
in reply to: JamesMaeding

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.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 4 of 8


@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.

Message 5 of 8

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.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 6 of 8


@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.

Message 7 of 8

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.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

Message 8 of 8
Balaji_Ram
in reply to: JamesMaeding

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost