From a63e76006c0b1958cf6f3f782fc119f19185fb12 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Fri, 21 Oct 2022 10:10:48 -0500 Subject: [PATCH] Use Environment.SpecialFolder.UserProfile, not SpecialFolder.Personal Context: https://github.com/dotnet/runtime/pull/68610 In .NET 8, a test using `SpecialFolder.Personal` failed with: [FAIL] Create table attempt failed! SQLite.SQLiteException: Could not open database file: /data/user/0/com.xamarin.customlinkdescriptionpreserve/files/Documents/TaskDB.db3 (CannotOpen) at SQLite.SQLiteConnection..ctor(SQLiteConnectionString ) at SQLite.SQLiteConnectionWithLock..ctor(SQLiteConnectionString ) at SQLite.SQLiteConnectionPool.Entry..ctor(SQLiteConnectionString ) at SQLite.SQLiteConnectionPool.GetConnectionAndTransactionLock(SQLiteConnectionString , Object& ) at SQLite.SQLiteConnectionPool.GetConnection(SQLiteConnectionString ) at SQLite.SQLiteAsyncConnection.GetConnection() at SQLite.SQLiteAsyncConnection.<>c__DisplayClass33_0`1[[SQLite.CreateTableResult, SQLite-net, Version=1.7.335.0, Culture=neutral, PublicKeyToken=null]].b__0() at System.Threading.Tasks.Task`1[[SQLite.CreateTableResult, SQLite-net, Version=1.7.335.0, Culture=neutral, PublicKeyToken=null]].InnerInvoke() at System.Threading.Tasks.Task.<>c.<.cctor>b__273_0(Object ) at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread , ExecutionContext , ContextCallback , Object ) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread , ExecutionContext , ContextCallback , Object ) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& , Thread ) --- End of stack trace from previous location --- at LinkTestLib.Bug35195.AttemptCreateTable() All regression tests completed. In .NET 8+, we should use `SpecialFolder.UserProfile` instead. --- build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs | 2 +- src-ThirdParty/NUnitLite/Env.cs | 2 +- .../MSBuildDeviceIntegration/Resources/LinkDescTest/Bug35195.cs | 2 +- tests/Mono.Android-Tests/Mono.Data.Sqlite/SqliteTests.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs b/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs index 760479ee6f5..accb0405ad9 100644 --- a/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs +++ b/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs @@ -232,7 +232,7 @@ public static partial class Defaults public static partial class Paths { // Global, compile-time locations - public static readonly string HomeDir = Environment.GetFolderPath (Environment.SpecialFolder.Personal); + public static readonly string HomeDir = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile); public static readonly string BootstrapResourcesDir = Path.Combine (BuildPaths.XAPrepareSourceDir, "Resources"); public static readonly string BuildToolsDir = Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "build-tools"); public static readonly string BuildToolsScriptsDir = Path.Combine (BuildToolsDir, "scripts"); diff --git a/src-ThirdParty/NUnitLite/Env.cs b/src-ThirdParty/NUnitLite/Env.cs index 0d9a547f5d8..5bac1bdfca7 100644 --- a/src-ThirdParty/NUnitLite/Env.cs +++ b/src-ThirdParty/NUnitLite/Env.cs @@ -50,7 +50,7 @@ public class Env #if SILVERLIGHT || PocketPC || WindowsCE || NETCF public static string DocumentFolder = @"\My Documents"; #else - public static string DocumentFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal); + public static string DocumentFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); #endif } } diff --git a/tests/MSBuildDeviceIntegration/Resources/LinkDescTest/Bug35195.cs b/tests/MSBuildDeviceIntegration/Resources/LinkDescTest/Bug35195.cs index 874fc525038..8f2f29f91ce 100644 --- a/tests/MSBuildDeviceIntegration/Resources/LinkDescTest/Bug35195.cs +++ b/tests/MSBuildDeviceIntegration/Resources/LinkDescTest/Bug35195.cs @@ -12,7 +12,7 @@ public static string AttemptCreateTable () try { // Initialize the database name. const string sqliteFilename = "TaskDB.db3"; - string libraryPath = Environment.GetFolderPath (Environment.SpecialFolder.Personal); + string libraryPath = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile); string path = Path.Combine (libraryPath, sqliteFilename); var db = new SQLiteAsyncConnection (path); db.CreateTableAsync ().GetAwaiter ().GetResult (); diff --git a/tests/Mono.Android-Tests/Mono.Data.Sqlite/SqliteTests.cs b/tests/Mono.Android-Tests/Mono.Data.Sqlite/SqliteTests.cs index 321df6122cb..3b4e65bd53a 100644 --- a/tests/Mono.Android-Tests/Mono.Data.Sqlite/SqliteTests.cs +++ b/tests/Mono.Android-Tests/Mono.Data.Sqlite/SqliteTests.cs @@ -41,7 +41,7 @@ static ItemsDb () ItemsDb () { - dbPath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), fileName); + dbPath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.UserProfile), fileName); } SqliteConnection GetConnection ()