AnsweredAssumed Answered

access violation exception

Question asked by James Mikel on Nov 11, 2015
Latest reply on Nov 13, 2015 by Jacob Corder

Hello,

I am getting the following in the application events viewer.   the application accesses swCustomPropertyManager.GetNames() method without throwing an error...Not sure why the Get3-5 methods are causing the error below.  Please help.

 

...

Exception Info: System.AccessViolationException

Stack:

   at SldWorks.CustomPropertyManagerClass.Get3(System.String, Boolean, System.String ByRef, System.String ByRef)

...

 

This is a standalone windows application that that uses the .interop.sldworks.dll and interop.swconst.dll to open selected files and extract the custom and config specific properties.

I only get the error when running on the clients' system.

Client's system is Windows 7.  Solidworks 2015.

I have tried Get3, Get4 and Get5 all with the same results.  Any help would be greatly appreciated.

 

        public bool Export(String swFile)

        {

            var success = true;

            ErrorMsg = String.Empty;

            swApp = new SldWorks();

 

 

            //MessageBox.Show("before open doc");

            swModel = swApp.OpenDoc6(swFile, p, s, "", ref nErrors, ref nWarnings);

            //MessageBox.Show("after open doc");

            if (swModel == null)

            {

                ErrorMsg = "Model did not load";

                swApp.SendMsgToUser2("Assembly not loaded", stop, ok);

                swModel = null;

                swApp = null;

                RecordError(ErrorMsg);

                success = false;

            }

            if (swModel.GetType() != p)

            {

                ErrorMsg = "Selected SLDPRT file is not a part doc.";

                swApp.SendMsgToUser2("Assembly not loaded", stop, ok);

                swModel = null;

                swApp = null;

                RecordError(ErrorMsg);

                success = false;

            }

            //MessageBox.Show("before rebuild");

            swModel.Rebuild(rebuild);

            //MessageBox.Show("after rebuild");

 

 

            try

            {

                //MessageBox.Show("before save rebuild");

                swModel.Save();

                //MessageBox.Show("after save rebuild");

            }

            catch (Exception ex)

            {

                RecordError(ex.Message.ToString());

                success = false;

            }

            cInfo = new Custom();

            //MessageBox.Show("Model: " + swModel.GetTitle().Trim());

 

 

            var title = swModel.GetTitle().Trim();

            if (title.Length > 7)

            {

                if (title.EndsWith(".SLDPRT") || title.EndsWith(".SLDDRW"))

                {

                    cInfo.DrawNo = title.Replace(".SLDDRW", "").Replace(".SLDPRT", "");

                }

                else

                {

                    cInfo.DrawNo = title.Substring(1, 4);

                    //sDrawno = Mid(swModel.GetTitle, 1, InStr(Mid(swModel.GetTitle, 4, swModel.GetTitle.Length), "-") + 2)

                }

            }

            else

            {

                cInfo.DrawNo = title;

            }

 

 

            try

            {

                //MessageBox.Show("before GetCustomInfoNames");

 

 

                var cfm = (String[])swModel.ConfigurationManager.Document.GetCustomInfoNames();

                //MessageBox.Show("cfm count: " + cfm.Count().ToString());

 

 

                foreach (var ci in cfm)

                {

                    switch (ci)

                    {

                        case "PROJECT NAME":

                            cInfo.ProjectName = swModel.GetCustomInfoValue("", ci);

                            break;

                        case "PROJECT NUMBER":

                            cInfo.ProjectNumber = swModel.GetCustomInfoValue("", ci);

                            break;

                        case "COLOR":

                            cInfo.Color = swModel.GetCustomInfoValue("", ci);

                            break;

                        case "PRODUCT NUMBER":

                            cInfo.ProductNumber = swModel.GetCustomInfoValue("", ci);

                            break;

                        default:

                            break;

                    }

                }

            }

            catch (Exception ex)

            {

                //swApp.CloseDoc(swFile);

                ErrorMsg = swFile + " custom info caused: " + ex.Message.ToString();

                RecordError(ErrorMsg);

                success = false;

            }

            finally

            {

                swApp.CloseDoc(swFile);

            }

 

 

            lCS = new lConfigSpecific();

            try

            {

                //MessageBox.Show("before ConfigSpecific Open Doc");

 

 

                swModel = swApp.OpenDoc6(swFile, 1, 1, "", ref nErrors, ref nWarnings);

                //MessageBox.Show("after Open doc");

 

 

                swApp.SetCurrentWorkingDirectory(swModel.GetPathName().Substring(0, swModel.GetPathName().LastIndexOf("\\")));

                //MessageBox.Show("after SetCurrentWorkingDirectory");

 

 

                var names = (String[])swModel.GetConfigurationNames();

                foreach (var name in names)

                {

                    //MessageBox.Show("before Extension");

 

 

                    swModelDocExt = swModel.Extension;

                    //MessageBox.Show("after extension");

 

 

                    swCustomPropertyManager = swModelDocExt.CustomPropertyManager[name];

                    //MessageBox.Show("after CustomProperty");

                    //MessageBox.Show(name + " : " + swCustomPropertyManager.Count.ToString());

 

 

                    var ncs = new ConfigSpecific { Config = name };

                    var customProps = (String[])swCustomPropertyManager.GetNames();

                    //MessageBox.Show("after Custom Property GetNames");

 

 

                    foreach (string cp in customProps)

                    {

                        //MessageBox.Show("Inside Custom Props: " + cp);

 

 

                        String val;

                        String valout;

                        //bool resolved;

                        bool UpToDate;

                        switch (cp)

                        {

                            case "CONFIG WEIGHT":

                                UpToDate = swCustomPropertyManager.Get3(cp, false, out val, out valout);

                                MessageBox.Show(valout);

                                //status = swCustomPropertyManager.Get4(cp, false, out val, out valout);

                                ncs.ConfigWeight = Decimal.Parse(valout);

                                break;

                            case "CONFIG VOLUME":

                                UpToDate = swCustomPropertyManager.Get3(cp, false, out val, out valout);

                                ncs.ConfigVolume = Double.Parse(valout);

                                break;

                            case "QTY":

                                UpToDate = swCustomPropertyManager.Get3(cp, false, out val, out valout);

                                ncs.Qty = valout.ToUpper() == "TBD" ? 0 : Int32.Parse(valout);

                                break;

                            case "LOCATION":

                                UpToDate = swCustomPropertyManager.Get3(cp, false, out val, out valout);

                                ncs.Location = valout;

                                break;

                            case "SAW CUT":

                                UpToDate = swCustomPropertyManager.Get3(cp, false, out val, out valout);

                                ncs.SawCut = valout.ToUpper() != "NO";

                                break;

                            default:

                                var donothing = String.Empty;

                                //RecordError("Custom Property not handled: " + cp + " Drawing: " + swFile);

                                break;

                    }

                    }

                    lCS.Add(ncs);

                }

                swApp.CloseDoc(swFile);

 

 

            }

            catch (Exception ex)

            {

                ErrorMsg = swFile + " config specifics caused: " + ex.Message.ToString();

                swApp.CloseDoc(swFile);

                RecordError(ex.Message.ToString());

                success = false;

            }

            return success;

        }

 

 

    }

Outcomes