From f6287f7b668b4f52614add2eb45b1135f8bfcc25 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Wed, 23 Aug 2023 10:29:35 +0800 Subject: [PATCH 1/2] Fsdk.Tests: include TSV in legacy proj It was only tested in non-legacy (dotnet v6 or newer). --- Fsdk.Tests/Fsdk.Tests-legacy.fsproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Fsdk.Tests/Fsdk.Tests-legacy.fsproj b/Fsdk.Tests/Fsdk.Tests-legacy.fsproj index c022c4d2..33ebcd3d 100644 --- a/Fsdk.Tests/Fsdk.Tests-legacy.fsproj +++ b/Fsdk.Tests/Fsdk.Tests-legacy.fsproj @@ -48,6 +48,7 @@ + From 7a4b950e70ddb5f50ecd7842d24b8e6aedb360c4 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Tue, 22 Aug 2023 20:10:21 +0800 Subject: [PATCH 2/2] Fsdk/Misc: fix NRE if legacy When running TSV unit tests in legacy framework (e.g. Mono), a NRE was being thrown; I guess because in that case the function GetEntryAssembly() was returning null. This fix is kinda ugly but is anyway affecting a part of the code that I plan to retire soon (cause it's API wrapped under LEGACY_FRAMEWORK ifdef). --- Fsdk/Misc.fs | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Fsdk/Misc.fs b/Fsdk/Misc.fs index 79e9f0f8..174a9e74 100644 --- a/Fsdk/Misc.fs +++ b/Fsdk/Misc.fs @@ -39,17 +39,32 @@ module Misc = #if LEGACY_FRAMEWORK // this below is crazy but is to avoid # char being ignored in Uri.LocalPath property, see https://stackoverflow.com/a/41203269 let private currentExeUri = - Uri(Uri.EscapeUriString(Assembly.GetEntryAssembly().CodeBase)) + let entryAssembly = Assembly.GetEntryAssembly() + + if isNull entryAssembly then + None + else + Uri(Uri.EscapeUriString(entryAssembly.CodeBase)) |> Some let private currentExe = - FileInfo( - sprintf - "%s%s" - (Uri.UnescapeDataString(currentExeUri.PathAndQuery)) - (Uri.UnescapeDataString(currentExeUri.Fragment)) - ) + match currentExeUri with + | None -> None + | Some currentExeUri -> + FileInfo( + sprintf + "%s%s" + (Uri.UnescapeDataString(currentExeUri.PathAndQuery)) + (Uri.UnescapeDataString(currentExeUri.Fragment)) + ) + |> Some let rec private FsxOnlyArgumentsInternalFsx(args: list) = + let currentExe = + if currentExe.IsNone then + failwith "Could not get EntryAssembly" + else + currentExe.Value + match args with | [] -> [] | head :: tail -> @@ -96,6 +111,12 @@ module Misc = // likely running a fsxc-ed assembly from an .fsx script (so 'dotnet someFile.fsx.dll someArg1' instead of 'dotnet fsi someFile.fsx someArg1') List.skip 1 cmdLineArgs #else + let currentExe = + if currentExe.IsNone then + failwith "Could not get EntryAssembly" + else + currentExe.Value + let isFsi = String.Equals( currentExe.Name,