Reply

accessing Property.Value property throws exception

[ Edited ]

 

MS Visual Studio 2003  Version 7.1.3088

MS .NET Framework 1.1 Version 1.1.4322 SP1

Solid Edge 18.00.12.03

using:  Interop.SolidEdgeFileProperties v1.0

ID:{AED8FE52-3129-11D1-BC83-0800360E1E02}\1.0\0\tlbimp

Programming in C#

I've searched around here and found the good help about accessing the SE file properties, thanks to all for questions and answers.

I have question about accessing the Value property from ((Properties)PropertySets[ 0 ] ) [ 8 ] and [ 9 ]  I started out with nested for loops indexes i and j, both starting at 1 per the thread: 'Fileproperties not working with vb.net'

I was printing the name and value of the PropterySets and Properties along with the .Count of each in a text box and noticed I was missing on item from each 'list'.  Oh yeah, need to change the "

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

 

Additional information: Unspecified error

 

"Unspecified error," handy.  After trouble shooting, 4 convolutions of staring inner index at 0/1and outer index at 0/1 I determined the problem to only be in the ProptertySet [ 0 ].  Checking the value of the inner index at the exception break it is at 8.  So I just went through the 17 properties of PropertySet [ 0 ] brute force (no for loop) and commented out the

((Property)((Properties)filePropertySets[ 0 ] ) [ 8 ] ).Value

line.  then had to also comment out the [ 9 ] as well.  The names of those two parameters are "Total Editing Time" and "Last Print Date" respectively.

Has anyone else had problems accessing the .Value property of these two Properties?

 

The Code:

            SolidEdgeFileProperties.PropertySets filePropertySets =

               new SolidEdgeFileProperties.PropertySetsClass();

 

            filePropertySets.Open(this.openFileDialog1.FileName, true);

 

            SolidEdgeFileProperties.Properties fileProperties;

            SolidEdgeFileProperties.Property fileProperty;

 

 

            this.richTextBox2.AppendText("filePropterySets.Count: " +

               filePropertySets.Count + "\n\r");

            for (int i = 1; i

            {

               fileProperties = (Properties)filePropertySets;

               this.richTextBox2.AppendText("   fileProperties[" +

                  i + "].Name: " + fileProperties.Name + "\n\r" +

                  "   fileProperties.Count: " + fileProperties.Count +

                  "\n\r");

               for (int j = 0; j

               {

                  fileProperty = (Property)fileProperties[j];

                  this.richTextBox2.AppendText("      " +

                     fileProperty.Name + ": " +

                     fileProperty.Value + "\n\r");

               }

            }

 

Edited twice in attempt to fix formatting errors.  BTW, is there a way to encapsulate the code so that it doesn't get littered with emotiocons and what not?

 

 

Posted by: Benjamin Nemec
Post date: 10/9/2007 8:46:41 AM

7 REPLIES

RE: accessing Property.Value property throws exception

[ Edited ]

 

My first response will be to address the formatting issue. You need to use the following html syntax:

* Spaces added to avoid filters. You will need to remove them when you use them.

 

Code goes here...

 

 

Posted by: Jason Newell
Post date: 10/16/2007 4:27:10 PM

RE: accessing Property.Value property throws exception

[ Edited ]

I wish that I had a good answer to this problem but in C# for some reason when dealing with SolidEdgeFileProperties API, I get an exception any time I try to call any method or property but using Reflection works perfectly. I think I've tried this recently in VB.NET and I did not have to use Reflection like I'm having to do here. I really just don't know why at this point.

 

Sorry for the ugly code but it works.

 

 

using SolidEdgeFileProperties;

using System;

using System.Collections.Generic;

using System.Runtime.InteropServices;

using System.Text;

 

namespace SEFilePropExample

{

class Program

{

static void Main(string[] args)

{

SolidEdgeFileProperties.PropertySets propertySets = null;

SolidEdgeFileProperties.Properties properties = null;

SolidEdgeFileProperties.Property property = null;

object[] arguments = null;

 

try

{

Type t = Type.GetTypeFromProgID("SolidEdge.FileProperties");

propertySets = Activator.CreateInstance(t) as SolidEdgeFileProperties.PropertySets;

if (propertySets != null)

{

arguments = new object[] { @"C:\Part1.par", true };

propertySets.GetType().InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, propertySets, arguments);

int propertySetCount = (int)propertySets.GetType().InvokeMember("Count", System.Reflection.BindingFlags.GetProperty, null, propertySets, null);

 

for (int i = 0; i

{

arguments = new object[] { i };

properties = (SolidEdgeFileProperties.Properties)propertySets.GetType().InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, propertySets, arguments);

 

string propertySetName = (string)properties.GetType().InvokeMember("Name", System.Reflection.BindingFlags.GetProperty, null, properties, null);

int propertiesCount = (int)properties.GetType().InvokeMember("Count", System.Reflection.BindingFlags.GetProperty, null, properties, null);

 

Console.WriteLine(propertySetName);

 

for (int j = 0; j

{

arguments = new object[] { j };

property = (SolidEdgeFileProperties.Property)properties.GetType().InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, properties, arguments);

 

string propertyName = String.Empty;

object propertyValue = String.Empty;

 

try

{

propertyName = (string)property.GetType().InvokeMember("Name", System.Reflection.BindingFlags.GetProperty, null, property, null);

propertyValue = property.GetType().InvokeMember("Value", System.Reflection.BindingFlags.GetProperty, null, property, null);

}

catch (System.Exception ex)

{

propertyValue = ex.Message;

}

 

Console.WriteLine("\t{0} = {1}", propertyName, propertyValue.ToString());

}

}

}

 

}

catch (System.Exception ex)

{

Console.WriteLine(ex.Message);

}

finally

{

if (property != null) { Marshal.ReleaseComObject(property); property = null; }

if (properties != null) { Marshal.ReleaseComObject(properties); properties = null; }

if (propertySets != null)

{

propertySets.GetType().InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, propertySets, null);

Marshal.ReleaseComObject(propertySets);

}

}

}

}

}

 

 

Posted by: Jason Newell
Post date: 10/16/2007 5:01:37 PM

RE: accessing Property.Value property throws exception

[ Edited ]

Jason, thank you for the posts and code. I need to make time to learn some html basics!

 

It will have to study your code for a while to figure out what exactly your doing, I haven't used System.Reflection yet so a bunch of that is new to me. If I cannot figure something out, you'll probably get bothered again.

 

Thanks again.

 

BTW, in case anyone would like to know, I am trying to help our IT department by getting an exploded BOM from a solid edge assembly and save the needed part/subassembly and connected draft(s) info in a delimited text file so they can parse it into our Oracle database system. There are packaged softs out for that, but didn't find any that would do what we needed.

 

Posted by: Benjamin Nemec
Post date: 10/17/2007 4:04:25 AM

RE: accessing Property.Value property throws exception

[ Edited ]

Ben,

 

I should have mentioned that using Reflection is not always necessary. It seems to be for the SolidEdgeFileProperty API but I know for a fact that all of the other API it is not. Not all of the time anyways. I only use Reflection when the normal Interop stuff does not work.

 

Bottom line, COM programming in .NET sucks! There I said it, now I feel better

 

Posted by: Jason Newell
Post date: 10/17/2007 4:11:39 AM

RE: accessing Property.Value property throws exception

[ Edited ]

 

Well that didn't take long!

 

I set up console project, compiled and crash.

 

Just to double check what dll or tlb are you referencing to get the SolidEdgeFileProperties? Also what version of Solid Edge is it from? I assume those dlls change sometimes with the version?

propertySets.GetType().InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, propertySets, arguments);

 

throws an exception every time. I've added a File.Exists(@C:\Part1.par) to help make sure the file path exists. I'd never seen the '@' before a path string before, or just never understood it, a little crash course on that. Wearing out my 'F1' key!

 

A lot of firsts here, I assume the Activator.CreateInstance is a less implicit version of the 'new' keyword? But am not certain of the other differences.

The InvokeMember, I kinda understand calls method, or accesses properties or field but the difference between using that and just the '.' is still in the black to me.

 

So trying to trouble shoot the exception, I noticed your not setting the PropertySets interface variable to a PropertySetsClass instance. To get the code I posted to work for the rest of the properties I had to declare the variable as an interface but set it to the PropertySetsClass. Found that here http://edndoc.esri.com/arcobjects/9.0/ArcGISDevHelp/DevelopmentEnvs/DotNet/SystemComObject.htm

before doing that I recall that .NET (or whatever) could not determine it's type and the .GetType() method just returned System.__ComObject.

 

I think I understand >whathow

 

Needless to say most of this stuff is over my head.

 

Stepping back a moment, is there metadata available about the properitySets structures given the SE file type? I thought I was doing well when I was pulling the desired properties out of the asm files but wasn't happy about using magic numbers to access the specific properties. Now I see that the structures must be different for parts then they are for assemblies. I tried using the SolidEdgeFileProperties.PropertyIDs enumerator, but I must be using it wrong as it doesn't get the matching property.

 

If / when you get a chance I will make use of any hints you have. Otherwise I'll be here Googling and wearing the ink off the 'F1' key.

 

Thank you much.

 

Posted by: Benjamin Nemec
Post date: 10/18/2007 8:56:28 AM

RE: accessing Property.Value property throws exception

[ Edited ]

Posted By Ben on 10/18/2007 1:56 PM

 

Well that didn't take long!

 

I set up console project, compiled and crash.

 

Just to double check what dll or tlb are you referencing to get the SolidEdgeFileProperties? Also what version of Solid Edge is it from? I assume those dlls change sometimes with the version? yes to referencing SolidEdgeFileProperties. Solid Edge V20 is what I used.

propertySets.GetType().InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, propertySets, arguments);

 

throws an exception every time. I've added a File.Exists(@C:\Part1.par) to help make sure the file path exists. What is the exception?

I'd never seen the '@' before a path string before, or just never understood it, a little crash course on that. Wearing out my 'F1' key!

If you don't use the @ to prefix a string, you'll have to use escapes. i.e. "C:\\Part1.par" instead of @"C:\Part1.par"

A lot of firsts here, I assume the Activator.CreateInstance is a less implicit version of the 'new' keyword? But am not certain of the other differences.

It's a stable way to create COM objects in .NET. If you haven't heard me say it before, COM programming in .NET sucks!The InvokeMember, I kinda understand calls method, or accesses properties or field but the difference between using that and just the '.' is still in the black to me.

 

This is called "Late Binding". Normally you want to avoid it like a bad habit but in this case, it was the only thing that worked.So trying to trouble shoot the exception, I noticed your not setting the PropertySets interface variable to a PropertySetsClass instance. To get the code I posted to work for the rest of the properties I had to declare the variable as an interface but set it to the PropertySetsClass. Found that here http://edndoc.esri.com/arcobjects/9.0/ArcGISDevHelp/DevelopmentEnvs/DotNet/SystemComObject.htm

before doing that I recall that .NET (or whatever) could not determine it's type and the .GetType() method just returned System.__ComObject.

 

Yeah, it's a crap shoot trying to figure out which interface to use. I try one and if it works, I'm golden I think I understand >whathow

 

No, reflection is actually very cool because it allows you to make calls on object w/o knowing their types. Classic COM has this same feature via the IDispatch interface. Google for IDispatch and you'll see an Invoke() method.Needless to say most of this stuff is over my head.

 

Stepping back a moment, is there metadata available about the properitySets structures given the SE file type? I thought I was doing well when I was pulling the desired properties out of the asm files but wasn't happy about using magic numbers to access the specific properties. Now I see that the structures must be different for parts then they are for assemblies. I tried using the SolidEdgeFileProperties.PropertyIDs enumerator, but I must be using it wrong as it doesn't get the matching property.

 

If / when you get a chance I will make use of any hints you have. Otherwise I'll be here Googling and wearing the ink off the 'F1' key.

 

Thank you much.

 

  My code demonstrates how to enumerate all PropertySets of a file and each Properties collection of each PropertySet. There are a number of ways to access each collections item. Usually, we can get away with something like propertySets["Custom"]["My Custom Property"], but it just does not seem to work for use in C#. I actually just got off a project where I had to use this API using C#. After I coded the whole thing using reflection, I ended up scrapping the whole **bleep** thing and doing it in C++. The C++ version was so much easier. Imagine that. Let me know if there is anything else I can do to help. Upload a .zip of your entire solution if you want me to try what you have.

 

Posted by: Jason Newell
Post date: 10/18/2007 4:35:45 PM

RE: accessing Property.Value property throws exception

[ Edited ]

Jason, I'm sorry for not specifying the exception. The message in the console shows, "Exception has been thrown by the target of an invocation." However when I went to check it out today it worked fine, then I realized that I had the file open in SE every time I tried it before. So it was just file sharing issues.

 

Posted by: Benjamin Nemec
Post date: 10/22/2007 11:07:37 AM