fsprojects / FSharp.TypeProviders.SDK

The SDK for creating F# type providers
https://fsprojects.github.io/FSharp.TypeProviders.SDK/
MIT License
298 stars 94 forks source link

Compiler is unable to load 3rd-party assembly if Runtime&Design-Time component contains type inherited from type defined in 3rd-party assembly #274

Closed sergey-tihon closed 4 years ago

sergey-tihon commented 5 years ago

Description

When I add type OptionConverter inherited from JsonConverter that is defined inside Newtonsoft.Json.dll

open Newtonsoft.Json

type OptionConverter() =
    inherit JsonConverter() // Type from Newtonsoft.Json

to runtime&design time assemblies, compilation fails with error

error FS3031 : The type provider '/Users/sergey/github/SwaggerProvider2/src/SwaggerProvider.Runtime/bin/Debug/net45/SwaggerProvider.Runtime.dll' reported an error : Assembly attribute 'TypeProviderAssemblyAttribute' refers to a designer assembly 'SwaggerProvider.DesignTime.dll' which cannot be loaded or doesn't exist. Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [/Users/sergey/github/SwaggerProvider2/tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj]

serialization_fs_ _swaggerprovider2

but when I comment class with inheritance OptionConverter but leave usage of Newtonsoft.Json.dll from other places - it loads Newtonsoft.Json.dll correctly.

There is an another error on the screenshot (but it is not related to dependency resolution) - this version is in inherit branch - https://github.com/sergey-tihon/SwaggerProvider2/commit/62a9d46880ffe51822facac3d82dceda9776dc75

serialization_fs_ _swaggerprovider2

Repro steps

  1. Clone repo https://github.com/sergey-tihon/tp-inherit-bug
  2. dotnet build

Expected behavior

Successful compilation

Actual behavior

error FS3031 : The type provider '/Users/sergey/github/SwaggerProvider2/src/SwaggerProvider.Runtime/bin/Debug/net45/SwaggerProvider.Runtime.dll' reported an error : Assembly attribute 'TypeProviderAssemblyAttribute' refers to a designer assembly 'SwaggerProvider.DesignTime.dll' which cannot be loaded or doesn't exist. Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [/Users/sergey/github/SwaggerProvider2/tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj]

Known workarounds

I guess that it should be possible to define such types in another assembly and load as dependency... but i did not try it yer (I hope that @dsyme know the line when we forgot to remap types ;-) )

Related information

Tarmil commented 5 years ago

I get the same error when using an external type in the signature of a method in the TPDTC. Although in my case it's a runtime method I don't actually need in the TPDTC, so I can just #if it out.

sergey-tihon commented 5 years ago

Thank you @Tarmil for the idea, seems that I also can use this workaround and do not include custom JsonConverters into design-time assembly and compile them only into Runtime assembly.

I also created simpler repro for this bug - https://github.com/sergey-tihon/tp-inherit-bug and updated Repro steps in this issue.

Tarmil commented 4 years ago

@sergey-tihon Your repro now runs successfully, without even having to update ProvidedTypes.*. I'm guessing this has been fixed in the compiler some time during the last year and a half then?

Tarmil commented 4 years ago

My error case in Bolero seems fixed too, I can remove my #ifs and it works.

sergey-tihon commented 4 years ago

Thank you @Tarmil, you are right, it works now.