diff --git a/src/VisualStudio/CSharp/Test/PersistentStorage/SQLitePersistentStorageTests.cs b/src/VisualStudio/CSharp/Test/PersistentStorage/SQLitePersistentStorageTests.cs index 262de16db13008499b93c262ac97ac22122e855e..ed86c298b2a97f16d714990ccda6fef584509e00 100644 --- a/src/VisualStudio/CSharp/Test/PersistentStorage/SQLitePersistentStorageTests.cs +++ b/src/VisualStudio/CSharp/Test/PersistentStorage/SQLitePersistentStorageTests.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Linq; -using System.Threading.Tasks; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.SolutionSize; using Microsoft.CodeAnalysis.SQLite; @@ -17,11 +15,6 @@ namespace Microsoft.CodeAnalysis.UnitTests.WorkspaceServices /// public class SQLitePersistentStorageTests : AbstractPersistentStorageTests { - static SQLitePersistentStorageTests() - { - Assert.True(SQLitePersistentStorageService.TryInitializeLibraries()); - } - internal override IPersistentStorageService GetStorageService(IPersistentStorageLocationService locationService, ISolutionSizeTracker solutionSizeTracker, IPersistentStorageFaultInjector faultInjector) => new SQLitePersistentStorageService(_persistentEnabledOptionService, locationService, solutionSizeTracker, faultInjector); diff --git a/src/Workspaces/Core/Desktop/Workspace/SQLite/SQLitePersistentStorageService.cs b/src/Workspaces/Core/Desktop/Workspace/SQLite/SQLitePersistentStorageService.cs index a4913783a1c8b8ff47da5f732086096600051419..817d5fd6b9a9ef01a13496e2b390f72abf858073 100644 --- a/src/Workspaces/Core/Desktop/Workspace/SQLite/SQLitePersistentStorageService.cs +++ b/src/Workspaces/Core/Desktop/Workspace/SQLite/SQLitePersistentStorageService.cs @@ -23,7 +23,7 @@ internal partial class SQLitePersistentStorageService : AbstractPersistentStorag [DllImport("kernel32.dll")] private static extern IntPtr LoadLibrary(string dllToLoad); - internal static bool TryInitializeLibraries() => s_initialized.Value; + private static bool TryInitializeLibraries() => s_initialized.Value; private static readonly Lazy s_initialized = new Lazy(() => TryInitializeLibrariesLazy()); @@ -88,6 +88,13 @@ protected override string GetDatabaseFilePath(string workingFolderPath) protected override bool TryOpenDatabase( Solution solution, string workingFolderPath, string databaseFilePath, out IPersistentStorage storage) { + if (!TryInitializeLibraries()) + { + // SQLite is not supported on the current platform + storage = null; + return false; + } + // try to get db ownership lock. if someone else already has the lock. it will throw var dbOwnershipLock = TryGetDatabaseOwnership(databaseFilePath); if (dbOwnershipLock == null) diff --git a/src/Workspaces/Core/Desktop/Workspace/Storage/PersistenceStorageServiceFactory.cs b/src/Workspaces/Core/Desktop/Workspace/Storage/PersistenceStorageServiceFactory.cs index bf85cbcff8f414691bd7535ed4432e86e95585eb..38162c6b2efe9d2b784e4b80d705b0a34b2781c2 100644 --- a/src/Workspaces/Core/Desktop/Workspace/Storage/PersistenceStorageServiceFactory.cs +++ b/src/Workspaces/Core/Desktop/Workspace/Storage/PersistenceStorageServiceFactory.cs @@ -28,13 +28,7 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices) switch (database) { case StorageDatabase.SQLite: - if (!SQLitePersistentStorageService.TryInitializeLibraries()) - { - break; - } - var locationService = workspaceServices.GetService(); - if (locationService != null) { return new SQLitePersistentStorageService(optionService, locationService, _solutionSizeTracker);