Generated types with custom attributes (including setting hideObjectMethods or nonNullable to true) from design-time libraries are not processed by the internal ProvidedTypesContext, and can therefore cause the compiled host application to reference the wrong versions. In my case, this is causing compiled applications to reference the ambient version of FSharp.Core used within Visual Studio at design time, because the TypeProviderEditorHideMethodsAttribute and AllowNullLiteralAttribute types are defined there.
This is roughly related to Microsoft/visualfsharp#3049 and Microsoft/visualfsharp#2399, and has the same end-result for my purposes, but both of those issues were opened prior to the recent refactoring of this SDK which automatically creates cross-targeting type providers. As my current code is my first generative type provider, I do not know if the previous ProvidedTypesContext would have handled this, but I can try to reproduce the issue with an old version of the SDK if needed.
Repro steps
Please provide the steps required to reproduce the problem
Create a generative type provider with the current code from this SDK (sample repro below)
Create a host application that uses the generative type provider, and references an old version of FSharp.Core
Build the host application while making use of the type provider, and review the compiled assembly's references
Expected behavior
The library versions referenced as part of the host application's project file should be the versions referenced in the compiled assembly.
Actual behavior
The ambient version of any referenced assemblies are used, rather than the ones specified in the project file.
Known workarounds
Do not use custom attributes from the ambient libraries. Besides any intentionally-used attributes, this additionally means not setting hideObjectMethods or nonNullable to true when creating ProvidedTypeDefinition values.
Related information
Operating system: Windows 10 1803
Branch: Current master, as of commit f0c4a6300db313eb2616c4f792cd6ae68c255e56
.NET Runtime, CoreCLR or Mono Version: Targeting .NET Framework 4.5, ambient version is 4.7.2
Performance information, links to performance testing scripts: N/A
Sample type provider that reproduces this:
namespace Some.Name.Space
open ProviderImplementation
open ProviderImplementation.ProvidedTypes
open Microsoft.FSharp.Quotations
[<Microsoft.FSharp.Core.CompilerServices.TypeProvider>]
type TestProvider (typeProviderConfig) as providerThis =
inherit TypeProviderForNamespaces(typeProviderConfig)
let targetNamespace = "Some.Name.Space"
let executingAssembly = System.Reflection.Assembly.GetExecutingAssembly()
let SampleProviderType =
let baseType = ProvidedTypeDefinition(executingAssembly, targetNamespace, "TestProvider", Some typeof<obj>, isErased = false)
baseType.DefineStaticParameters(
[ ProvidedStaticParameter("SomeParam", typeof<string>, "") ],
(fun typeName _ ->
let asm = ProvidedAssembly()
// Change the line below to resolve this issue
let t = ProvidedTypeDefinition(asm, targetNamespace, typeName, Some typeof<obj>, hideObjectMethods = true, isErased = false)
asm.AddTypes [t]
t
))
baseType
do
providerThis.AddNamespace(targetNamespace, [SampleProviderType])
[<assembly: Microsoft.FSharp.Core.CompilerServices.TypeProviderAssembly>]
do ()
Description
Generated types with custom attributes (including setting
hideObjectMethods
ornonNullable
totrue
) from design-time libraries are not processed by the internalProvidedTypesContext
, and can therefore cause the compiled host application to reference the wrong versions. In my case, this is causing compiled applications to reference the ambient version ofFSharp.Core
used within Visual Studio at design time, because theTypeProviderEditorHideMethodsAttribute
andAllowNullLiteralAttribute
types are defined there.This can probably be solved by implementing
ProvidedTypesContext.convCustomAttributesDataToTgt
, which currently has aTODO
note suggesting this.This is roughly related to Microsoft/visualfsharp#3049 and Microsoft/visualfsharp#2399, and has the same end-result for my purposes, but both of those issues were opened prior to the recent refactoring of this SDK which automatically creates cross-targeting type providers. As my current code is my first generative type provider, I do not know if the previous
ProvidedTypesContext
would have handled this, but I can try to reproduce the issue with an old version of the SDK if needed.Repro steps
Please provide the steps required to reproduce the problem
Create a generative type provider with the current code from this SDK (sample repro below)
Create a host application that uses the generative type provider, and references an old version of
FSharp.Core
Build the host application while making use of the type provider, and review the compiled assembly's references
Expected behavior
The library versions referenced as part of the host application's project file should be the versions referenced in the compiled assembly.
Actual behavior
The ambient version of any referenced assemblies are used, rather than the ones specified in the project file.
Known workarounds
Do not use custom attributes from the ambient libraries. Besides any intentionally-used attributes, this additionally means not setting
hideObjectMethods
ornonNullable
totrue
when creatingProvidedTypeDefinition
values.Related information
Sample type provider that reproduces this: