4 Replies Latest reply on Jul 6, 2017 8:18 AM by Adam Davidson

    Error creating PMP: Specified cast is not valid

    Jon Kennedy

      Hi!

       

      I'm working through Luke's excellent second book "Solidworks API: Advanced Product Development".

      I'm trying to get the main Property Manager Page example from the book working.

      It registers fine as an add-in but when it comes to creating the property manager page it comes up with this error:

      "Error creating PMP: Specified cast is not valid"

       

      I thought I may have made a mistake along the way so re-created the project using the example files that come with the book but get the same message.

       

      The very basic example from earlier in the book where a Property Manager Page is created but has no event hooks / handlers works fine. My vague suspicion is its something to do with the difference between the Sldworks and ISldworks interfaces since this is different between the two examples in the book. But I'm pretty new to this game and am at a loss!

       

      Anyone had a similar problem?

      Anyone succesfully created this example with Soldiworks 2013 64bit?

       

      Cheers

      Jon

        • Re: Error creating PMP: Specified cast is not valid
          Timothy Root

          The PMP is a part of the API that has changed significantly between SW versions.  I have had issues where I am trying to use code for a newer version of SW with an older version of SW.  I don't think I got that particular error though.  Can you isolate what line of code the error occurs on?  That might lead you to a solution right there.  If not, post a copy of the problem line here for others to look at.

            • Re: Error creating PMP: Specified cast is not valid
              Artem Taturevych

              Make sure that the Property Manager Page handler you are passing to SldWorks::CreatePropertyManagerPage is a public class which implements the IPropertyManagerPage2Handler9 interface (or any other versions of interface). And this handler or the assembly where the handler is a ComVisible assembly registered for COM Interops.

              ____________________________________________________

              Regards,

              Artem Taturevych, Application Engineer at Intercad (Australia)

               

              translationXpert – add-in to translate SolidWorks models

              myIntercad an integrated tool for SolidWorks Professionals

              LinkedIn SolidWorks API Education Group

                • Re: Error creating PMP: Specified cast is not valid
                  Jon Kennedy

                  Hello Timothy / Artem,

                  Many thanks for your replies.

                  There is a try catch block around the "swApp.CreatePropertyManagerPage" line. It is the catch that is creating the error I'm seeing. So a more dramatic error. The "swApp.CreatePropertyManagerPage" command doesn't run to the level where its own error messages can be read.

                  The PMP handler class is public.

                  It uses the IPropertyManagerPage2Handler6 version of this interface but other samples in the book used this version so that in itself shouldn't be a problem.

                  The problem solving part of my mind wants to work out what is going on. But it is only a sample from a book. Perhaps it worked 4 years / 4 versions of SW ago when the book was written.

                  So I'll probably put it to one side.

                  I have subsequently found a different example project via the API helpfile that succefully creates both a PMP and Taskpane addin's so I think I will use this as the foundation for my Add-In and forget the book example.

                  Many thanks for your help!

                  jon

                  • Re: Error creating PMP: Specified cast is not valid
                    Adam Davidson

                    > Make sure that the Property Manager Page handler you are passing to SldWorks::CreatePropertyManagerPage is a public class.

                    That was it for me. My class was internal, adding public fixed it. Thanks for the suggestion:

                     

                    [ComVisible(true)]
                    public class SystemUnitPropertyPage : IPropertyManagerPage2Handler9 { ... }