Reply

Late binding Problems...

[ Edited ]

 

Hello once again,

I'm running into a COM Exception when trying to late bind the method GetFamilyOfAssemblyMemberNames of SolidEdgeFileProperties.PropertySets:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80020005): Typkonflikt. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))

 

Hope anyone has an idea what I'm doing wrong...

 

Here is my code:

static bool isFamilyOfAssembly(string file)

        {

            SolidEdgeFileProperties.PropertySets _propertySets = null;                        

 

            object[] parameters = null;

            int MemberCount = 0;

            Array MemberNames = null;           

            parameters = new object[] { file, MemberCount, MemberNames };

           try

            {               

 

 

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

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

 

                if (_propertySets != null)

                {

                    ParameterModifier arrPmods = new ParameterModifier(3);

                    arrPmods[0] = false;

                    arrPmods[1] = true;

                    arrPmods[2] = true;

                    ParameterModifier[] mods = { arrPmods };                    

 

                    _propertySets.GetType().InvokeMember("GetFamilyOfAssemblyMemberNames",

                         BindingFlags.InvokeMethod, null, _propertySets, parameters, mods, null, null);

                    MemberCount = (int)parameters[1];

                    MemberNames = parameters[2] as Array;

                }

                foreach (string item in MemberNames)

                {

                    Console.WriteLine(item);

                }

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex);

            }

            finally

            {

                if (_propertySets != null)

                {

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

                    Marshal.ReleaseComObject(_propertySets);

                }

            }

            return true;

        }

 

 

 

Posted by: Seb Sosna
Post date: 2/10/2008 10:25:31 PM

3 REPLIES

RE: Late binding Problems...

[ Edited ]

I usually have really bad experiences with the SolidEdgeFileProperties API every time I try to use it in .NET. I'll take a stab at getting your code to work this weekend and let you know.

 

Posted by: Jason Newell
Post date: 2/15/2008 6:35:08 AM

RE: Late binding Problems...

[ Edited ]

 

>I'll take a stab at getting your code to work this weekend and let you know.

That would be great! Thanks Jason!

 

 

Posted by: Seb Sosna
Post date: 2/16/2008 3:43:36 AM

RE: Late binding Problems...

[ Edited ]

 

Hello,

news on the issue:

I've found out that SEFileProperties have problems/will crash if the thread which it is running in, does not have the STAThread attribute set. If the thread is not single threaded apartment state then every method of SEFileProperties call will result in a crash (corrupt memory).

Therefore, no need for reflection when calling SEFileProperties methods.

hth

regards,

Sibi

 

Posted by: Seb Sosna
Post date: 4/18/2008 8:31:06 AM