【Sourcetree】解決閃退問題

某天重開機之後就開不了 Sourcetree 了,查了一下發現應該是 Windows 更新導致的問題。

C:\Users\ama\AppData\Local\Atlassian\SourceTree\sourcetree.log 錯誤訊息如下:

ERROR [2023-06-15 09:20:33,821] [1] [Sourcetree.Composition.VSMef.Net48.VSMefCompositionManager] [Log] - Unable to load MEF components
System.InvalidOperationException: 序列未包含項目
   於 System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   於 Microsoft.VisualStudio.Composition.PartDiscovery.GetElementTypeFromMany(Type type)
   於 Microsoft.VisualStudio.Composition.RuntimeComposition.RuntimeImport.get_ImportingSiteTypeWithoutCollection()
   於 Microsoft.VisualStudio.Composition.RuntimeComposition.RuntimeImport.get_IsLazy()
   於 Microsoft.VisualStudio.Composition.RuntimeComposition.RuntimeImport.get_LazyFactory()
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.GetValueForImportSite(RuntimePartLifecycleTracker importingPartTracker, RuntimeImport import)
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.SatisfyImports()
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.SatisfyImmediateImports()
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState)
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState)
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose()
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0()
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.GetValueForImportElement(RuntimePartLifecycleTracker importingPartTracker, RuntimeImport import, RuntimeExport export, Func`3 lazyFactory)
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.GetValueForImportSite(RuntimePartLifecycleTracker importingPartTracker, RuntimeImport import)
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.<CreateValue>b__10_0(RuntimeImport import)
   於 System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   於 System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   於 System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue()
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create()
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState)
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState)
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose()
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.<>c__DisplayClass15_0.<GetExportedValueHelper>b__0()
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.GetValueForImportElement(RuntimePartLifecycleTracker importingPartTracker, RuntimeImport import, RuntimeExport export, Func`3 lazyFactory)
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.GetValueForImportSite(RuntimePartLifecycleTracker importingPartTracker, RuntimeImport import)
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.<CreateValue>b__10_0(RuntimeImport import)
   於 System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   於 System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   於 System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   於 Microsoft.VisualStudio.Composition.RuntimeExportProviderFactory.RuntimeExportProvider.RuntimePartLifecycleTracker.CreateValue()
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.Create()
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveNext(PartLifecycleState nextState)
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.MoveToState(PartLifecycleState requiredState)
   於 Microsoft.VisualStudio.Composition.ExportProvider.PartLifecycleTracker.GetValueReadyToExpose()
   於 System.Lazy`1.CreateValue()
   於 System.Lazy`1.LazyInitValue()
   於 Microsoft.VisualStudio.Composition.NetFxAdapters.MefV1ExportProvider.<>c__DisplayClass12_0.<UnwrapExport>b__1()
   於 System.ComponentModel.Composition.Primitives.Export.get_Value()
   於 System.ComponentModel.Composition.ReflectionModel.ImportingItem.Cast(Type type, Export export)
   於 System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.SetImport(ImportingItem item, Export[] exports)
   於 System.ComponentModel.Composition.Hosting.ImportEngine.PartManager.TrySetImport(ImportDefinition import, Export[] exports)
   於 System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSubset(PartManager partManager, IEnumerable`1 imports, AtomicComposition atomicComposition)
   於 System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportsStateMachine(PartManager partManager, ComposablePart part)
   於 System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager, ComposablePart part, Boolean shouldTrackImports)
   於 System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImportsOnce(ComposablePart part)
   於 System.ComponentModel.Composition.Hosting.CompositionContainer.SatisfyImportsOnce(ComposablePart part)
   於 System.ComponentModel.Composition.AttributedModelServices.SatisfyImportsOnce(ICompositionService compositionService, Object attributedPart)
   於 Sourcetree.Composition.VSMef.Net48.VSMefCompositionManager.<Compose>d__5.MoveNext()

最後成功的解法為刪除C:\Users\ama\AppData\Local\Atlassian\SourceTree.exe_Url_zeqdug2r5zpvv2zmyrbkerxd220ogx5n\3.4.8.0\Composition.cache


網路上還有看到幾種嘗試解法

  1. 取消 Windows Update
    • 失敗,依然啟動不了程式
  2. 直接點擊執行檔
    • C:\Users\ama\AppData\Local\SourceTree\app-3.4.8\SourceTree.exe
    • 失敗
  3. 重新安裝 Sourcetree
    • 需先刪除 C:\Users\ama\AppData\Local\SourceTree
    • 需先刪除 C:\Users\ama\AppData\Local\Atlassian
    • 這個我沒試過,但應該是最終手段了,真的其他方式都解決不了再使用這招吧!

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *