Linq.Expression.Optimizer icon indicating copy to clipboard operation
Linq.Expression.Optimizer copied to clipboard

invalid reference in package for net45 version

Open proff opened this issue 3 years ago • 5 comments

Description

изображение

Repro steps

I have legacy solution with webforms, blazor and multitarget net48/netstandard21 projects. WebForms project version don't use optimizer yet, but have indirectly reference to it. When i add Swashbuckle to WebForms project it dosn't start at all.

  1. Create multitarget net48/netstandard21 project.

  2. Add Linq.Expression.Optimizer package to it.

  3. Create WebForms project.

  4. Add reference to first project.

  5. Add reference to Swashbuckle package (it have reference to WebActivatorEx package).

You don't need actually use Linq.Expression.Optimizer or Swashbuckle

Expected behavior

Web site started succesfully,

Actual behavior

bin folder contains FSarp.Core version 4.4.1 Exception on start: [FileLoadException: Could not load file or assembly 'FSharp.Core, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)] System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) +0 System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +197 System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +166 System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) +156 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +612 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +149 WebActivatorEx.AssemblyExtensions.GetActivationAttributes(Assembly assembly) +164 WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +321 WebActivatorEx.ActivationManager.RunPreStartMethods(Boolean designerMode) +55 WebActivatorEx.ActivationManager.Run() +74

[InvalidOperationException: The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Could not load file or assembly 'FSharp.Core, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).] System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection1 methods, Func1 setHostingEnvironmentCultures) +890 System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +167 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +133 System.Web.Compilation.BuildManager.ExecutePreAppStart() +178 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +746

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Could not load file or assembly 'FSharp.Core, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +552 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +122 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +737

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4210.0

Known workarounds

Add FSharp.Core 4.5.4 package to WebFroms project

proff avatar Oct 27 '20 20:10 proff

Any suggestions how to fix this? Should the FSharp Core dependency be updated? I think there is 5.0.0 already available... Binding redirects may also help.

Thorium avatar Oct 27 '20 21:10 Thorium

Binding redirects help, but it should be used only for version upgrade (not downgrade). FSharp Core dependency can not be upgraded for net35 version (if you want continue support this) because next version does not support them. I don't know well f#, paket and what tooling version you are used for build package, but it seems f# 4.5 used for net45 and f# 4.1 for others. For this configuration package metadata should be:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>Linq.Expression.Optimizer</id>
    <version>1.0.14</version>
    <title>Linq.Expression.Optimizer</title>
    <authors>Tuomas Hietanen</authors>
    <owners>Tuomas Hietanen</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <licenseUrl>https://github.com/Thorium/Linq.Expression.Optimizer/blob/master/LICENSE.txt</licenseUrl>
    <projectUrl>https://github.com/Thorium/Linq.Expression.Optimizer</projectUrl>
    <iconUrl>https://raw.githubusercontent.com/Thorium/Linq.Expression.Optimizer/master/docs/files/img/logo.png</iconUrl>
    <description>Lightweight optimizer of System.Linq.Expression expressions. Just basic boolean algebra and reductions, constant and tuple/anonymous type eliminations. For side-effect free Expressions. No compilation-subjective optimizations.</description>
    <summary>Lightweight optimizer of System.Linq.Expression expressions. Just basic boolean algebra and reductions, constant and tuple/anonymous type eliminations. For expressions that are not compiled to IL.</summary>
    <releaseNotes>Look inside a WhereSelectEnumerableIterator, #9</releaseNotes>
    <copyright>Copyright 2015</copyright>
    <tags>LINQ Expression Expressions tree expressiontree expression-tree IQueryable System.Linq.Expressions optimise optimize compile boolean algebra deMorgan reduction optimizer optimiser</tags>
    <dependencies>
      <group targetFramework=".NETFramework3.5">
        <dependency id="FSharp.Core" version="4.1.18" />
      </group>
      <group targetFramework=".NETFramework4.5">
        <dependency id="FSharp.Core" version="4.5.4" />
      </group>
      <group targetFramework=".NETStandard1.6">
        <dependency id="FSharp.Core" version="4.1.18" />
      </group>
    </dependencies>
  </metadata>
</package>

Linq.Expression.Optimizer.1.0.14.zip

Tested in my solution in net48/webforms/entityframework and netstandard/blazor/entityframeworkcore

proff avatar Oct 28 '20 10:10 proff

Thanks, this was very helpful. Probably you'd want to do

    <dependencies>
      <group targetFramework="net35">
        <dependency id="FSharp.Core" version="[4.1.18]" />
      </group>
      <group targetFramework="net45">
        <dependency id="FSharp.Core" version="4.5.4" />
      </group>
      <group targetFramework="netstandard1.6">
        <dependency id="FSharp.Core" version="4.1.18" />
      </group>
    </dependencies>

...so that the 3.5 version is exact match and others are "or-more", so the corresponding paket.template would be:

dependencies
  framework: net35
    FSharp.Core = 4.1.18
  framework: net45
    FSharp.Core >= 4.5.4
  framework: netstandard1.6
    FSharp.Core >= 4.1.18

Thorium avatar Oct 28 '20 13:10 Thorium

Sorry, I didn't meant to close it just yet, but https://github.com/Thorium/Linq.Expression.Optimizer/commit/dfe1979d3ddc1d8c8e2c4332b6fd9bf60d45ecaf should fix the issue.

Thorium avatar Oct 28 '20 13:10 Thorium

This dependencies configuration is little better 👍

proff avatar Oct 28 '20 20:10 proff