// Copyright (c) 2020 Theodore Tsirpanis
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

namespace Farkle.Tools

open Farkle.Builder
open System
open System.Reflection

/// Loads the precompiled grammars from an assembly file.
type PrecompiledAssemblyFileLoader(path) =
    let resolver = PathAssemblyResolver([path; typeof<obj>.Assembly.Location])
    let loadContext = new MetadataLoadContext(resolver)
    let asm = loadContext.LoadFromAssemblyPath(path)
    let grammars = PrecompiledGrammar.GetAllFromAssembly asm

    member _.Grammars = grammars
    interface IDisposable with
        member _.Dispose() = loadContext.Dispose()

// Copyright (c) 2020 Theodore Tsirpanis
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT

namespace Farkle.Tools

open Farkle.Builder
open System
open System.Reflection

/// Loads the precompiled grammars from an assembly file.
type PrecompiledAssemblyFileLoader(path) =
    let resolver = PathAssemblyResolver([path; typeof<obj>.Assembly.Location])
    let loadContext = new MetadataLoadContext(resolver, typeof<obj>.Assembly.GetName().Name)
    let asm = loadContext.LoadFromAssemblyPath(path)
    let grammars = PrecompiledGrammar.GetAllFromAssembly asm

    member _.Grammars = grammars
    interface IDisposable with
        member _.Dispose() = loadContext.Dispose()

Revert "Do not specify a core assembly name in the precompiled assembly file loader."
Revert "Do not specify a core assembly name in the precompiled assembly file loader."

This reverts commit 06c10e885da4402aeab4c538666037e2060c7d67.
The removal of the core assembly name caused the loader to break. I hadn't understood the significance of that parameter.
When the MetadataLoadContext gets loaded, it tries to resolve and load the designated as core assembly. If we don't specify a name, it will try either "mscorlib", "netstandard" or "System.Runtime".
However, our resolver knows only about the assembly of object which is "System.Private.CoreLib", will not be able to resolve either of the three, and throw.