@@ -11,21 +11,21 @@ namespace Rubberduck.UI.Command.MenuItems.CommandBars
1111{ 
1212    public  class  SerializeProjectsCommandMenuItem  :  CommandMenuItemBase 
1313    { 
14-         public  SerializeProjectsCommandMenuItem ( SerializeDeclarationsCommand  command )  :  base ( command ) 
14+         public  SerializeProjectsCommandMenuItem ( SerializeProjectsCommand  command )  :  base ( command ) 
1515        { 
1616        } 
1717
1818        public  override  Func < string >  Caption  {  get  {  return  ( )  =>  "Serialize" ;  }  } 
1919        public  override  string  Key  =>  "SerializeProjects" ; 
2020    } 
2121
22-     public  class  SerializeDeclarationsCommand  :  CommandBase 
22+     public  class  SerializeProjectsCommand  :  CommandBase 
2323    { 
2424        private  readonly  RubberduckParserState  _state ; 
2525        private  readonly  IComProjectSerializationProvider  _serializationProvider ; 
2626        private  readonly  IComLibraryProvider  _comLibraryProvider ; 
2727
28-         public  SerializeDeclarationsCommand ( RubberduckParserState  state ,  IComProjectSerializationProvider  serializationProvider ,  IComLibraryProvider  comLibraryProvider )  
28+         public  SerializeProjectsCommand ( RubberduckParserState  state ,  IComProjectSerializationProvider  serializationProvider ,  IComLibraryProvider  comLibraryProvider )  
2929            :  base ( LogManager . GetCurrentClassLogger ( ) ) 
3030        { 
3131            _state  =  state ; 
@@ -49,19 +49,24 @@ protected override void OnExecute(object parameter)
4949
5050            foreach  ( var  project  in  _state . ProjectsProvider . Projects ( ) . Select ( proj =>  proj . Project ) ) 
5151            { 
52-                 foreach  ( var  reference   in  project . References . Select ( lib  =>   new   ReferenceInfo ( lib ) ) ) 
52+                 using  ( var  references   =  project . References ) 
5353                { 
54-                     var  library  =  _comLibraryProvider . LoadTypeLibrary ( reference . FullPath ) ; 
55-                     if  ( library  ==  null ) 
54+                     foreach  ( var  reference  in  references ) 
5655                    { 
57-                         Logger . Warn ( $ "Could not load library { reference . FullPath }  for serialization.") ; 
58-                         continue ; 
59-                     } 
56+                         var  info  =  new  ReferenceInfo ( reference ) ; 
57+                         reference . Dispose ( ) ; 
58+                         var  library  =  _comLibraryProvider . LoadTypeLibrary ( info . FullPath ) ; 
59+                         if  ( library  ==  null ) 
60+                         { 
61+                             Logger . Warn ( $ "Could not load library { info . FullPath }  for serialization.") ; 
62+                             continue ; 
63+                         } 
6064
61-                     var  type  =  new  ComProject ( library ,  reference . FullPath ) ; 
62-                     if  ( ! toSerialize . ContainsKey ( type . Guid ) ) 
63-                     { 
64-                         toSerialize . Add ( type . Guid ,  type ) ; 
65+                         var  type  =  new  ComProject ( library ,  info . FullPath ) ; 
66+                         if  ( ! toSerialize . ContainsKey ( type . Guid ) ) 
67+                         { 
68+                             toSerialize . Add ( type . Guid ,  type ) ; 
69+                         }                       
6570                    } 
6671                } 
6772            } 
0 commit comments