Message 1 of 11
Problem with MPolygon observed as ImpEntity

Not applicable
11-21-2007
12:46 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
In one of your clients, we currently have a quite big cadastre solution that contains different applications in different platforms. One of the key components of that solution is an AutoCAD Map application, actually deployed in about 30 workstations over the client's network.
The application was developed using:
• Oracle 9.2.1 / Spatial
• NET Framework 2.0 / C# (v2.0.50727)
• AutoCAD Map 2006
• .NET ObjectARX Wrappers (ver. 2006)
Each workstation have identical software installations:
• Microsoft Windows 2000 Professional + Service Pack 4
• Autodesk DWF Viewer
• Autodesk Map 3D 2006
• Autodesk Mapguide Dynamic Authoring Toolkit Release 6.5
• Autodesk Mapguide Viewer Activex Control Release 6.5
• Autodesk LandXML Reporting 6
• Oracle 9.2.1 Client Software
Now, in a specific point of the application, it needs to validate that every one of the selected objects in the current AMap document are actually of the "MPolygon" type. If that validation is ok, the selected objects are casted as actual MPolygon objects inside the code for future usage in the code.
The problem now is that in some worksatations, when the application starts the validation, it returns that the selected objects are "ImpEntity" and not "MPolygon". The validation of course can't complete successfully, and even if I bypass the validation, the objects can't be casted as MPolygons either, rising an application error.
After the first occurrence of this situation (which happens randomly in time), the application never come back to work properly again in that workstation, that is, it always return ImpEntity as the object type when selections are MPoligons.
For testing this situation I developed a small Amap command:
-----------------------------------------------------------------
1 #region TestTipoObjeto()
2 [Autodesk.AutoCAD.Runtime.CommandMethodAttribute("TestTipoObjeto")]
3 public void TestTipoObjeto()
4 {
5 testTipoObjeto();
6 }
7 #endregion
8
9 #region testTipoObjeto()
10 public void testTipoObjeto()
11 {
12 try
13 {
14 Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
15 acDoc.LockDocument();
16 ObjectIdCollection colObjectId = SelectObjects(acDoc, true);
17 if (colObjectId.Count > 0)
18 {
19 using (AcDb.Database db = acDoc.Database)
20 {
21 using (AcDb.Transaction trans = db.TransactionManager.StartTransaction())
22 {
23 string msg = string.Empty;
24 foreach (ObjectId objectId in colObjectId)
25 {
26 Entity dbObject = trans.GetObject(objectId, AcDb.OpenMode.ForRead) as Entity;
27
28 string entityType = dbObject.GetType().Name;
29 msg += ">> ACad Type = " + entityType + "\n";
30
31 object obj = dbObject.AcadObject;
32 PropertyDescriptor pd = TypeDescriptor.GetProperties(obj)["ObjectName"];
33 string baseTipo = (string)pd.GetValue(obj);
34 msg += ">> Base Type = " + baseTipo + "\n";
35
36 try
37 {
38 AcDb.MPolygon acMPolygon = (AcDb.MPolygon)trans.GetObject(objectId, AcDb.OpenMode.ForWrite, true);
39 msg += ">> Cast OK \n";
40 }
41 catch (Exception ex)
42 {
43 msg += ">> Error: " + ex.Message.ToString() + "\n";
44 }
45
46 trans.Commit();
47 }
48 AcadEditor.WriteMessage("\nTipos de Objeto: " + msg + " \n");
49 }
50 }
51 }
52 }
53 catch (System.Exception ex)
54 {
55 AcadEditor.WriteMessage("\nError Message: " + ex.Message.ToString() + " \n");
56 AcadEditor.WriteMessage("\nError Stack: " + ex.StackTrace.ToString() + " \n");
57 }
58 }
59 #endregion
-----------------------------------------------------------------
If the application is working properly:
a) The string entityType at line 28 returns "MPolygon"
b) The string baseTipo at line 33 returns "AcDbMPolygon"
c) The cast at line 38 works well
If the application is broken:
a) The string entityType at line 28 returns "ImpEntity"
b) The string baseTipo at line 33 returns "AcDbMPolygon"
c) The cast at line 38 works well
The objects in the document can be objects that were drawn by the user in his current session, of objects that were retrieved from the Oracle Database.
Now, my current research on this issue:
First, i found the following thead in this forum:
http://discussion.autodesk.com/thread.jspa?threadID=604438
In that thread, Tony Tanzillo wrote: "ImpEntity is one of the managed wrapper types that get created, if there is no application-specific managed wrapper implemented for a given custom object type, or the managed wrappers for the custom object are not being loaded", wich seems quite logical.
So, my question is: How can I know exactly which is the managed wrapper for "MPolygon" that is apparently not loaded? And of course, how can I load it on demand? (i.e.: when the application starts)
Meanwhile, I found a temporary "workaround". On a "broken" machine, I open AMap, go to Tools -> Options -> Profiles, click on "Reset" (which unload every application inside AMap) and finally I import a profile file that was generated in a clean "not broken" machine. I quickly realized that the operation that solved the problem was reseting the actual profile, and not loading a new one, but it was necessary to restore the original applications inside AMap (like toolbars, etc).
Obviously, for our client, this isn't a solution for the problem, in any way, but it helped somehow.
In the other hand, it was difficult to reproduce the problem, as we didn't know how to make AMap behave that way. But a few days ago, I found something really strange. In my development workstation (that is not broken), if I open AMap (using the desktop icon), draw a MPolygon, and finally run my "TestTipoObjeto" command over that object, it tells me that it's actually an "MPolygon".
But if I save that document as a new .DWG, close AMap, and reopen it using doubleclicking the .DWG I just created... when I run the command over the saved polygon it return that it's an "ImpEntity" object. I'm not quite sure, but this is actually my only way to reproduce the issue in the development enviroment.
Finally, using an external Windows Application (also developed with C#) I tried to compare the running processes and dependent modules on my machine, when the app return "MPolygon" and when the app return "ImpEntity", maybe with the hope of finding the "missing managed wrapper", with no success.
So, I'm really stuck with this problem now.
Any help will be really appreciated.
Thanks in advance.
The application was developed using:
• Oracle 9.2.1 / Spatial
• NET Framework 2.0 / C# (v2.0.50727)
• AutoCAD Map 2006
• .NET ObjectARX Wrappers (ver. 2006)
Each workstation have identical software installations:
• Microsoft Windows 2000 Professional + Service Pack 4
• Autodesk DWF Viewer
• Autodesk Map 3D 2006
• Autodesk Mapguide Dynamic Authoring Toolkit Release 6.5
• Autodesk Mapguide Viewer Activex Control Release 6.5
• Autodesk LandXML Reporting 6
• Oracle 9.2.1 Client Software
Now, in a specific point of the application, it needs to validate that every one of the selected objects in the current AMap document are actually of the "MPolygon" type. If that validation is ok, the selected objects are casted as actual MPolygon objects inside the code for future usage in the code.
The problem now is that in some worksatations, when the application starts the validation, it returns that the selected objects are "ImpEntity" and not "MPolygon". The validation of course can't complete successfully, and even if I bypass the validation, the objects can't be casted as MPolygons either, rising an application error.
After the first occurrence of this situation (which happens randomly in time), the application never come back to work properly again in that workstation, that is, it always return ImpEntity as the object type when selections are MPoligons.
For testing this situation I developed a small Amap command:
-----------------------------------------------------------------
1 #region TestTipoObjeto()
2 [Autodesk.AutoCAD.Runtime.CommandMethodAttribute("TestTipoObjeto")]
3 public void TestTipoObjeto()
4 {
5 testTipoObjeto();
6 }
7 #endregion
8
9 #region testTipoObjeto()
10 public void testTipoObjeto()
11 {
12 try
13 {
14 Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
15 acDoc.LockDocument();
16 ObjectIdCollection colObjectId = SelectObjects(acDoc, true);
17 if (colObjectId.Count > 0)
18 {
19 using (AcDb.Database db = acDoc.Database)
20 {
21 using (AcDb.Transaction trans = db.TransactionManager.StartTransaction())
22 {
23 string msg = string.Empty;
24 foreach (ObjectId objectId in colObjectId)
25 {
26 Entity dbObject = trans.GetObject(objectId, AcDb.OpenMode.ForRead) as Entity;
27
28 string entityType = dbObject.GetType().Name;
29 msg += ">> ACad Type = " + entityType + "\n";
30
31 object obj = dbObject.AcadObject;
32 PropertyDescriptor pd = TypeDescriptor.GetProperties(obj)["ObjectName"];
33 string baseTipo = (string)pd.GetValue(obj);
34 msg += ">> Base Type = " + baseTipo + "\n";
35
36 try
37 {
38 AcDb.MPolygon acMPolygon = (AcDb.MPolygon)trans.GetObject(objectId, AcDb.OpenMode.ForWrite, true);
39 msg += ">> Cast OK \n";
40 }
41 catch (Exception ex)
42 {
43 msg += ">> Error: " + ex.Message.ToString() + "\n";
44 }
45
46 trans.Commit();
47 }
48 AcadEditor.WriteMessage("\nTipos de Objeto: " + msg + " \n");
49 }
50 }
51 }
52 }
53 catch (System.Exception ex)
54 {
55 AcadEditor.WriteMessage("\nError Message: " + ex.Message.ToString() + " \n");
56 AcadEditor.WriteMessage("\nError Stack: " + ex.StackTrace.ToString() + " \n");
57 }
58 }
59 #endregion
-----------------------------------------------------------------
If the application is working properly:
a) The string entityType at line 28 returns "MPolygon"
b) The string baseTipo at line 33 returns "AcDbMPolygon"
c) The cast at line 38 works well
If the application is broken:
a) The string entityType at line 28 returns "ImpEntity"
b) The string baseTipo at line 33 returns "AcDbMPolygon"
c) The cast at line 38 works well
The objects in the document can be objects that were drawn by the user in his current session, of objects that were retrieved from the Oracle Database.
Now, my current research on this issue:
First, i found the following thead in this forum:
http://discussion.autodesk.com/thread.jspa?threadID=604438
In that thread, Tony Tanzillo wrote: "ImpEntity is one of the managed wrapper types that get created, if there is no application-specific managed wrapper implemented for a given custom object type, or the managed wrappers for the custom object are not being loaded", wich seems quite logical.
So, my question is: How can I know exactly which is the managed wrapper for "MPolygon" that is apparently not loaded? And of course, how can I load it on demand? (i.e.: when the application starts)
Meanwhile, I found a temporary "workaround". On a "broken" machine, I open AMap, go to Tools -> Options -> Profiles, click on "Reset" (which unload every application inside AMap) and finally I import a profile file that was generated in a clean "not broken" machine. I quickly realized that the operation that solved the problem was reseting the actual profile, and not loading a new one, but it was necessary to restore the original applications inside AMap (like toolbars, etc).
Obviously, for our client, this isn't a solution for the problem, in any way, but it helped somehow.
In the other hand, it was difficult to reproduce the problem, as we didn't know how to make AMap behave that way. But a few days ago, I found something really strange. In my development workstation (that is not broken), if I open AMap (using the desktop icon), draw a MPolygon, and finally run my "TestTipoObjeto" command over that object, it tells me that it's actually an "MPolygon".
But if I save that document as a new .DWG, close AMap, and reopen it using doubleclicking the .DWG I just created... when I run the command over the saved polygon it return that it's an "ImpEntity" object. I'm not quite sure, but this is actually my only way to reproduce the issue in the development enviroment.
Finally, using an external Windows Application (also developed with C#) I tried to compare the running processes and dependent modules on my machine, when the app return "MPolygon" and when the app return "ImpEntity", maybe with the hope of finding the "missing managed wrapper", with no success.
So, I'm really stuck with this problem now.
Any help will be really appreciated.
Thanks in advance.