Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.IO.FileNotFoundException: Could not load file or assembly 'JasperFx.Core, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified #662

Closed
nkosi23 opened this issue Dec 14, 2023 · 3 comments
Labels
wontfix This will not be worked on

Comments

@nkosi23
Copy link

nkosi23 commented Dec 14, 2023

Describe the bug
I do not know if the JasperFx.Core project is still being maintained since it has had no activity in over a year, and the description says that Wolverine is its successor, I therefore repost this issue here and apologize if this is not appropriate.

When running a basic empty ASP.NET Core project in F# configured to use a library calling JasperFx under the hoods (Oakton, Wolverine, etc...) I get the following exception on application startup:

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'JasperFx.Core, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

File name: 'JasperFx.Core, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null'
   at Oakton.CommandFactory..ctor()
   at Oakton.CommandLineHostingExtensions.ApplyOaktonExtensions(IHostBuilder builder)

What is strange is that the dll is correctly copied to the output directory, however its metadata are a bit strange: namely the version is set to 0.0.0.0, here is what JetBrains Rider displays about the assembly referenced by the project

Name: JasperFx.Core
Full name: JasperFx.Core, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Location: /home/username/.nuget/packages/jasperfx.core/1.5.1/lib/net7.0/JasperFx.Core.dll
Mvid: 0726d806-ac4a-4c0f-8c5e-398ba3a43e29
Platform: net7.0

Needless to say that this issue is quite blocking, running a project with something as basic as the below should reproduce the exception:

    let exitCode = 0
    let builder = WebApplication.CreateBuilder(args)
    builder.Host.ApplyOaktonExtensions()

    builder.Services.AddControllers()
    builder.Services.AddResourceSetupOnStartup()

   let app = builder.Build()

  app.RunOaktonCommands(args) |> Async.AwaitTask 
  
  exitCode

If I remove the lines regarding oakton and try to configure Wolverine using the UseWolverine method of the hostbuilder, this exception will be thrown at that point instead. I've seen people succefully boostrap JasperFx-based projects using F# like here so I'm a bit puzzled.

Everything works properly in the C# version but I am in the process of migrating all the projects to F#. Any idea or pointers? Cleaning/Rebuilding does not help unfortunately. The project targets .NET 7:

<PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <GenerateDocumentationFile>true</GenerateDocumentationFile>
        <OutputType>Exe</OutputType>
    </PropertyGroup>

 <ItemGroup>
        <PackageReference Include="FSharp.SystemTextJson" Version="1.2.42"/>
        <PackageReference Include="JasperFx.Core" Version="1.5.1"/>
        <PackageReference Include="MailKit" Version="4.2.0"/>
        <PackageReference Include="Marten" Version="6.4.0"/>
        <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0"/>
        <PackageReference Include="WolverineFx" Version="1.8.0"/>
        <PackageReference Include="WolverineFx.Http" Version="1.8.0"/>
    </ItemGroup>

To Reproduce
Steps to reproduce the behavior:

  1. Create a new F# ASP.NET Core project referencing a JasperFx based project
  2. Run the application
  3. The exception is produced

Expected behavior
The application is launched

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Linux x64
  • Browser N/A
  • Version openSUSE
@nkosi23
Copy link
Author

nkosi23 commented Dec 15, 2023

I managed to have a more detailed stacktrace:

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'JasperFx.Core, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

File name: 'JasperFx.Core, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null'
   at System.ModuleHandle.ResolveType(QCallModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
   at JasperFx.Core.Reflection.ReflectionExtensions.HasAttribute[T](Assembly provider)
   at Oakton.CommandFactory.<>c.<RegisterCommandsFromExtensionAssemblies>b__33_0(Assembly a)
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.OrderedEnumerable`1.ToArray()
   at JasperFx.Core.TypeScanning.AssemblyFinder.FindAssemblies(Func`2 filter, String assemblyPath, Action`1 logFailure, Boolean includeExeFiles)
   at JasperFx.Core.TypeScanning.AssemblyFinder.FindAssemblies(Action`1 logFailure, Func`2 filter, Boolean includeExeFiles)
   at JasperFx.Core.TypeScanning.AssemblyFinder.FindAssemblies(Func`2 filter, Boolean includeExeFiles)
   at Oakton.CommandFactory.RegisterCommandsFromExtensionAssemblies()
   at Oakton.CommandLineHostingExtensions.ApplyOaktonExtensions(IHostBuilder builder)
   at Bonita.Online.Api.Program.main(String[] args) in /home/reddy/Workspace/source-code/Bonita.Online/Bonita.Online.Api/Program.fs:line 42

However I wasn't able to reproduce the issue using a minimalist F# created from scratch, the below works in a blank project:

// For more information see https://aka.ms/fsharp-console-apps

#nowarn "20"

open Microsoft.AspNetCore.Builder
open Oakton
open Oakton.Resources

let exitCode = 0

[<EntryPoint>]
let main args =
    printfn "Hello from F#"

    let builder = WebApplication.CreateBuilder(args)
    builder.Host.ApplyOaktonExtensions()
    builder.Services.AddResourceSetupOnStartup()

    let app = builder.Build()
    app.RunOaktonCommands(args) |> Async.AwaitTask

    exitCode

I am trying to figure out what's going on in my main project, nothing looks suspicious in the .fsproj file and the versions of the nuget packages referenced seem to be consistent:

@nkosi23
Copy link
Author

nkosi23 commented Dec 15, 2023

Progressing! Turns out this is actually a Wolverine issue. I managed to reproduce the issue by adding the Wolverine package to the minimal project. As soon as I did that the exception appeared on startup. So here is the situation:

  • Referencing Oakton alone did not produce the exception
  • Referencing Oakton + Marten did not produce the exception
  • Adding a reference to Wolverine introduced the exception. Adding the base Wolverine package alone produced the .dll not found exception with a different assembly, but adding a reference to Wolverine.Http produced the aforementioned exception relating to JasperFx.Core.

I have been able to fix this problem by upgrading Wolverine packages from version 1.10.1 to the latest version (1.12.4). However what is strange is that these issues did not occur in the C# project (when porting to F# I just kept the same versions of the NuGet packages).

I'll therefore leave this issue open for a bit so that hopefully the root cause can be identified lest the problem pops up again randomly during a minor package version update.

@jeremydmiller
Copy link
Member

Jasper is the old name for Wolverine, and that is no longer maintained as that became Wolverine. JasperFx.Core is a shared library used by Marten, Wolverine, and others that is actively maintained.

This sounds like a run of the mill Nuget reference problem which unfortunately happens quite often with projects that are moving. If you were on the latest Wolverine or Oakton, both are forcing you to the latest JasperFx.Core, which should knock out the problem.

There's nothing actionable here, so I am closing this one.

@jeremydmiller jeremydmiller added the wontfix This will not be worked on label Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants