giacomelli / GeneticSharp

GeneticSharp is a fast, extensible, multi-platform and multithreading C# Genetic Algorithm library that simplifies the development of applications using Genetic Algorithms (GAs).
MIT License
1.27k stars 332 forks source link

Runtime exception on .NET 4.6.2 #58

Closed jbrant closed 5 years ago

jbrant commented 5 years ago

I'm running Visual Studio 2013 targeting .NET 4.6.2 with GeneticSharp 2.4.0, and get the following runtime exception when attempting to instantiate a GeneticAlgorithm instance (specifically, when the task executor is set):

Could not load file or assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.

Is .NET Framework 4.6.2 still supported, or is .NET standard 2.0.0+ now required?

giacomelli commented 5 years ago

If you are just using GeneticSharp from Nuget, you can use it on VS 2013, but if you are building the GeneticSharp's source code from scratch, then you need to follow our guide: Building the whole solution.

What is your case?

jbrant commented 5 years ago

I'm installing via Nuget (i.e. not building from the source code).

giacomelli commented 5 years ago

The Nuget package (https://www.nuget.org/packages/GeneticSharp/) seems to have the right dependencies.

Could you please send, a minimum project sample with this problem happening?

I don't have VS 2013 here, but maybe I can spot what is the problem.

giacomelli commented 5 years ago

I've created a console project targeting 4.6.2 and I could not reproduce the error.

Can you try the project attached and compare it with your project? TestGeneticSharpNet462.zip

jbrant commented 5 years ago

Thank you very much for the exemplar project. I actually did still get the above-referenced error, but at compile time. Interestingly, if I commented out the TaskExecutor override in the GeneticAlgorithm object initializer block (i.e. TaskExecutor = new ParallelTaskExecutor()), this resolved the compilation error. but the same runtime exception was still thrown.

Specifically, this is the compilation error:

error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

jbrant commented 5 years ago

Quick update on this: the infrastructure framework DLLs (i.e. GeneticSharp.Infrastructure.Framework.dll) for both the netstandard2.0 and net462 targets have the same hash. Perhaps Nuget has the .NET standard build for both targets. This isn't the case for the domain DLL (GeneticSharp.Domain.dll), which would explain why the above-referenced error only occurs when interface with properties or methods from the infrastructure project.

It looks like the infrastructure DLL that's bundled with the domain project build will always be .NET standard regardless of target framework, so if the GeneticSharp Nuget package is using the infrastructure DLL from the domain build, then maybe that's what's causing the issue.

giacomelli commented 5 years ago

Yes, you'are right. I opened the assemblies from geneticsharp.2.4.0.nupkg\lib\net462 in ILSpy:

GeneticSharp.Domain.dll

image

GeneticSharp.Infrastructure.Framework.dll

image

GeneticSharp.Infrastructure.Framework.dll from net462 folder is using .NETStandard instead of .NET Framework.

I'll investigate what is wrong with project files or with the nuget generation.