public void Resolve(IVisio.Documents docs)
        {
            // first get the unique stencils (ignoring case)
            var comparer = System.StringComparer.CurrentCultureIgnoreCase;
            var unique_stencils = new HashSet<string>(comparer);
            foreach (var master_ref in this.master_ref_dic.Values)
            {
                unique_stencils.Add(master_ref.StencilName);
            }

            // for each unique stencil, load the stencil doc
            var name_to_stencildoc = new Dictionary<string, IVisio.Document>(comparer);
            foreach (var stencil in unique_stencils.Where(s=>s!=null))
            {
                // If a stencil was stencified open the stencil if needed
                var stencil_doc = docs.OpenStencil(stencil);
                if (stencil_doc == null)
                {
                    string msg = $"Failed to open stencil \"{stencil}\"";
                    throw new AutomationException(msg);
                }

                name_to_stencildoc[stencil] = stencil_doc;
            }

            // identify real master objects for all deferred shapes
            foreach (var master_ref in this.master_ref_dic.Values)
            {
                if (master_ref.VisioMaster == null)
                {
                    if (master_ref.StencilName != null)
                    {
                        // The stencil doc was specified so try to find the master in that stencil doc
                        var stencildoc = name_to_stencildoc[master_ref.StencilName];
                        var stencilmasters = stencildoc.Masters;

                        var master_object = this.TryGetMaster(stencilmasters, master_ref.MasterName);
                        if (master_object == null)
                        {
                            string msg =
                                $"No such master \"{master_ref.MasterName}\" in stencil \"{master_ref.StencilName}\"";
                            throw new AutomationException(msg);
                        }
                        master_ref.VisioMaster = master_object;                        
                    }
                    else
                    {
                        // the stencil doc was not specified so try to find the master int the current doc
                        var app = docs.Application;
                        var stencildoc = app.ActiveDocument;
                        var stencilmasters = stencildoc.Masters;

                        var master_object = this.TryGetMaster(stencilmasters, master_ref.MasterName);
                        if (master_object == null)
                        {
                            string msg =
                                $"No such master \"{master_ref.MasterName}\" in Active Document \"{stencildoc.Name}\"";
                            throw new AutomationException(msg);
                        }
                        master_ref.VisioMaster = master_object;
                    }
                }
            }
        }