Home

Trying to use Marten in LinqPad 8 causes System.IO.FileNotFoundException exception

edited December 2023

Running this code in LinqPad 8:

public async void Main() {

    var store = DocumentStore.For(MartenDb);

    using var querySession = store.QuerySession("DEFAULT");
    var fooModel = await querySession.Query<FooModel>().SingleOrDefaultAsync(x => x.Id == Guid.Parse("1de04917-c8a4-41b0-92c5-d5fda34e2a17"));

}

causes this weird exception:

System.IO.FileNotFoundException: Could not load file or assembly 'NuGet.Versioning, Version=6.7.0.127, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
File name: 'NuGet.Versioning, Version=6.7.0.127, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at System.Reflection.RuntimeAssembly.<InternalLoad>g____PInvoke|49_0(NativeAssemblyNameParts* __pAssemblyNameParts_native, ObjectHandleOnStack __requestingAssembly_native, StackCrawlMarkHandle __stackMark_native, Int32 __throwOnFileNotFound_native, ObjectHandleOnStack __assemblyLoadContext_native, ObjectHandleOnStack __retAssembly_native)
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
   at JasperFx.RuntimeCompiler.AssemblyGenerator.ReferenceAssembly(Assembly assembly)

The offending statement is the querySession.Query but I am a bit baffled as to why that happens so I was wondering if anyone has any ideas?

Comments

  • FYI, this example works in Visual Studio 2022.

  • Press Alt+Shift+R and take a look at JasperFx.RuntimeCompiler.AssemblyGenerator.ReferenceAssembly. Are there any clues in there?

  • edited December 2023

    Nothing that could hint to what is the problem. It probably expects to find an assembly but cannot find it so hence the exception I guess.

    I also forgot to add a line of the output in my previous post. The full output is:

    Could not make an assembly reference to LINQPad.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=21353812cd2a2db5
    
    System.IO.FileNotFoundException: Could not load file or assembly 'NuGet.Versioning, Version=6.7.0.127, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
    File name: 'NuGet.Versioning, Version=6.7.0.127, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
       at System.Reflection.RuntimeAssembly.<InternalLoad>g____PInvoke|49_0(NativeAssemblyNameParts* __pAssemblyNameParts_native, ObjectHandleOnStack __requestingAssembly_native, StackCrawlMarkHandle __stackMark_native, Int32 __throwOnFileNotFound_native, ObjectHandleOnStack __assemblyLoadContext_native, ObjectHandleOnStack __retAssembly_native)
       at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
       at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
       at JasperFx.RuntimeCompiler.AssemblyGenerator.ReferenceAssembly(Assembly assembly)
    

    Maybe that is the problem? I will try and load that Assembly manually and see if that works.

  • The problem can be seen from the code - it's recursively walking the entire dependency graph. Your query references LINQPad.Runtime (so that it can call methods such as Dump, and interact with the host), however LINQPad.Runtime has its own internal dependencies which shouldn't be walked. These include libraries such as NuGet.Versioning, which load into a private ALC. You need to find some way of telling this library to restrict the libraries it walks. I don't think this issue is unique to LINQPad.Runtime.

  • I see. Probably I should raise a bug then as this code is used by Marten.
    I will raise this with the developers as I have no idea how to "blacklist" those dependencies.
    Thank you! :)

Sign In or Register to comment.