Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Generated types with custom attributes can cause incorrect references at runtime #225
Generated types with custom attributes (including setting
This can probably be solved by implementing
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
Please provide the steps required to reproduce the problem
The library versions referenced as part of the host application's project file should be the versions referenced in the compiled assembly.
The ambient version of any referenced assemblies are used, rather than the ones specified in the project file.
Do not use custom attributes from the ambient libraries. Besides any intentionally-used attributes, this additionally means not setting
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 ()