Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9211765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:22:17+00:00 2026-06-18T01:22:17+00:00

I have a question related to the code provided in an answer to this

  • 0

I have a question related to the code provided in an answer to this question.

The problem I have is that the three referenced assmeblies (System.dll, FSharp.Core.dll, FSharp.Powerpack.dll) that are passed to CompilerParameters are not found at runtime. The error I get is:

unknown-file(0,0) : error 0: error FS0218: Unable to read assembly
‘c:\user s\utente\documents\visual studio
2010\Projects\TrashSolution\TrashSolution\bin\D ebug\FSharp.Core.dll’

How do I tell the compiler to search for these assemblies in the GAC, instead of the project’s bin directory? If I open a namespace in the code provided as a string, how do I know which assemblies to add? Where can I get this information?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:22:18+00:00Added an answer on June 18, 2026 at 1:22 am

    In the code from the answer you linked, there’s a line towards the bottom:

    let asm = Reflection.Assembly.LoadFrom(fileinfo.Value.FullName)
    

    If you call Reflection.Load instead and pass it the fully-qualified assembly name, it’ll try to load the assembly from the GAC (and a few other places, if the assembly isn’t in the GAC).

    let asm =
        Assembly.Load "SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3"
    

    If you don’t know the fully-qualified assembly name you have to create an AssemblyName with the simple name of the assembly, then call the Reflection.Load overload which takes an AssemblyName instead of a string.

    let asmName = AssemblyName "Your.Assembly.Name"
    let asm = Assembly.Load asmName
    

    As far as knowing which assemblies to load — I don’t think there’s a simple way to determine that programmatically. The only two solutions I can think of right now:

    1. If you have some knowledge about the code you’re being given (as a string), you could parse it with the FSharpCodeProvider and look at which namespaces/modules are opened and which types are used. If you’re looking to see if some particular namespace or type is used (i.e., that you would need to include an assembly reference for when compiling the code), you could create a Map (in your .fsx which is doing the compilation) of namespaces and/or type names to assembly names and use it to reference the appropriate assemblies.
    2. You could “brute-force” search the GAC, by using the semi-documented Fusion API to enumerate all of the assemblies installed in the GAC, then using Reflection to examine each assembly and determine if it’s one you require. This is likely to be extremely slow, so I’d avoid it at all costs. If you do decide to go this route, you must also use the Assembly.ReflectionOnlyLoad method to load the assemblies! This allows the assemblies to be unloaded after you finish examining them — if you use normal Reflection the assemblies can’t be unloaded and your program will likely crash with an OutOfMemoryException or similar.

    EDIT: Turns out that loading the assembly by its simple name succeeds in fsi and not in normal F# code because fsi automatically installs a handler for the AppDomain.AssemblyResolve event. This event is triggered by the CLR when you try to load an assembly and it can’t be resolved; the event provides a way for you to “manually” resolve the assembly and/or generate an assembly dynamically and return it.

    If you look at the FileNotFoundException raised when you try to run the code in an F# project, you’ll see something like this in the Fusion Log property of the exception:

    === Pre-bind state information ===
    LOG: User = Jack-Laptop\Jack
    LOG: DisplayName = System
     (Partial)
    WRN: Partial binding information was supplied for an assembly:
    WRN: Assembly Name: System | Domain ID: 1
    WRN: A partial bind occurs when only part of the assembly display name is provided.
    WRN: This might result in the binder loading an incorrect assembly.
    WRN: It is recommended to provide a fully specified textual identity for the assembly,
    WRN: that consists of the simple name, version, culture, and public key token.
    WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
    LOG: Appbase = file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/
    LOG: Initial PrivatePath = NULL
    Calling assembly : StackOverflow1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
    ===
    LOG: This bind starts in default load context.
    LOG: No application configuration file found.
    LOG: Using host configuration file: 
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
    LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
    LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System.DLL.
    LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System/System.DLL.
    LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System.EXE.
    LOG: Attempting download of new URL file:///C:/Users/Jack/Documents/Visual Studio 2010/Projects/StackOverflow1/StackOverflow1/bin/Debug/System/System.EXE.
    

    Looking towards the bottom of that log, you’ll see where the CLR searched for the assembly before it gave up.

    Here’s a simple handler to give you an idea of how to use the AppDomain.AssemblyResolve handler to manually resolve the assembly. (NOTE: The handler needs to be added before the code that attempts to load the assembly!)

    System.AppDomain.CurrentDomain.add_AssemblyResolve (
        System.ResolveEventHandler (fun _ args ->
            let resolvedAssembly =
                System.AppDomain.CurrentDomain.GetAssemblies ()
                |> Array.tryFind (fun loadedAssembly ->
                    // If this assembly has the same name as the one we're looking for,
                    // assume it's correct and load it. NOTE : It may not be the _exact_
                    // assembly we're looking for -- then you'll need to adjust the critera below.
                    args.Name = loadedAssembly.FullName
                    || args.Name = loadedAssembly.GetName().Name)
    
            // Return null if the assembly couldn't be resolved.
            defaultArg resolvedAssembly null))
    

    If you add that code to a new F# console project, followed by the code which uses AssemblyName with Assembly.Load, you should be able to load the System assembly because it’s referenced by default in an F# project and it’ll be loaded when you run the project. If you try to resolve System.Drawing, it’ll fail because our custom event handler can’t find the assembly. Obviously, if you need some more complicated assembly-resolving logic, you should build that into the event handler in whatever way makes sense for your application.

    Finally, here’s a link to the MSDN whitepaper mentioned in the exception message: Best Practices for Assembly Loading. It’s worth a read if you get stuck and can’t figure out how to resolve the assemblies you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Another question related to this one . I have a List<SortableObjects> that is the
Hi all I have seen all question related to this problem but couldn't find
This question is related to my education, with that said I wish to have
I have a question related to this one . I don't want to do
I have a question related to this one : I'm trying to attach an
This question is related to database/RDBMS where i have little knowledge regarding performance and
I have a design and object structuring related question. Here is the problem statement:
I have question related to what is done in SMS application is if i'm
I have a question related to understanding of how python dictionaries work. I remember
I have following event class. I have a question related to the Property method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.