static void SerializeObject(string path, object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            var t = Counters.ParserService.ObjectSerialized.BeginTiming(path);

            try {
                using (var fs = new FileStream(path, System.IO.FileMode.Create, FileAccess.Write)) {
                    using (var writer = new BinaryWriterWith7BitEncodedInts(fs)) {
                        lock (sharedSerializer) {
                            sharedSerializer.Serialize(writer, obj);
                        }
                    }
                }
            } catch (Exception e) {
                Console.WriteLine("-----------------Serialize stack trace:");
                Console.WriteLine(Environment.StackTrace);
                LoggingService.LogError("Error while writing type system cache. (object:" + obj.GetType() + ")", e);
            } finally {
                t.Dispose();
            }
        }
 void SaveToCache(string cacheFileName, DateTime lastWriteTime, LoadedAssembly asm)
 {
     if (cacheFileName == null)
     {
         return;
     }
     LoggingService.Debug("Serializing to " + cacheFileName);
     try {
         Directory.CreateDirectory(DomPersistencePath);
         using (FileStream fs = new FileStream(cacheFileName, FileMode.Create, FileAccess.Write)) {
             using (BinaryWriter writer = new BinaryWriterWith7BitEncodedInts(fs)) {
                 writer.Write(lastWriteTime.Ticks);
                 FastSerializer s = new FastSerializer();
                 s.Serialize(writer, asm);
             }
         }
     } catch (IOException ex) {
         LoggingService.Warn(ex);
         // Can happen if two SD instances are trying to access the file at the same time.
         // We'll just let one of them win, and instance that got the exception won't write to the cache at all.
         // Similarly, we also ignore the other kinds of IO exceptions.
     } catch (UnauthorizedAccessException ex) {
         LoggingService.Warn(ex);
     }
 }
 static void SaveToCache(string cacheFileName, IProjectContent pc)
 {
     try {
         Directory.CreateDirectory(Path.GetDirectoryName(cacheFileName));
         using (FileStream fs = new FileStream(cacheFileName, FileMode.Create, FileAccess.Write)) {
             using (BinaryWriter writer = new BinaryWriterWith7BitEncodedInts(fs)) {
                 writer.Write(cacheMagicNumber);
                 FastSerializer s = new FastSerializer();
                 s.Serialize(writer, pc);
             }
         }
     } catch (IOException ex) {
         LoggingService.Warn(ex);
         // Can happen if two SD instances are trying to access the file at the same time.
         // We'll just let one of them win, and the instance that got the exception won't write to the cache at all.
         // Similarly, we also ignore the other kinds of IO exceptions.
     } catch (UnauthorizedAccessException ex) {
         LoggingService.Warn(ex);
     }
 }