Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Providers design assembly required without direct reference. #585

Closed
matthid opened this issue Jun 18, 2016 · 3 comments
Closed

Type Providers design assembly required without direct reference. #585

matthid opened this issue Jun 18, 2016 · 3 comments
Labels

Comments

@matthid
Copy link
Contributor

matthid commented Jun 18, 2016

Repro steps

Provide the steps required to reproduce the problem

  1. git clone https://github.com/matthid/fcs_bug_585.git
  2. cd fcs_bug_585
  3. ./build.sh (git bash) or build.cmd

What this does is:

  1. Create library LibraryUsingTypeprovider with the following contents

    namespace LibraryUsingTypeprovider
    
    // This is only here, because otherwise the F# compiler is smart enough to optimize the reference away...
    open FSharp.Data
    open FSharp.Data.JsonExtensions
    
    module Wrapped =
    let useSomething (j : JsonValue) =
      j?Major.AsInteger()

    with a reference to FSharp.Data

  2. Create a console application Repro with

    open System
    open System.IO
    open System.Reflection
    
    let scriptFilePath = Path.GetFullPath @"myscript.fsx"
    // replace with path to the compiled LibraryUsingTypeprovider library.
    let someLib = Path.GetFullPath @"C:\PROJ\FSharp.Compiler.Service_585\bin/lib/LibraryUsingTypeprovider.dll"
    File.WriteAllText(scriptFilePath, @"
    #r """ + someLib.Replace(@"\", @"\\") + @"""
    open System
    Console.WriteLine(""TEST_OUTPUT"")");
    open Microsoft.FSharp.Compiler.Interactive.Shell
    
    [<EntryPoint>]
    let main args =
    let fsiConfig = FsiEvaluationSession.GetDefaultConfiguration()
    let fsiArgs = [| @"C:\fsi.exe" |]
    let inStream = new StringReader("")
    use session = FsiEvaluationSession.Create(fsiConfig, fsiArgs, inStream, Console.Out, Console.Error)
    session.EvalScriptNonThrowing scriptFilePath |> printfn "%A"
    //execScript scriptFilePath
    0

    with references to FSharp.Compiler.Service and LibraryUsingTypeprovider.

  3. Run Repro.exe

Expected behavior

Starting Target: RunRepro (==> BuildRepro)
bin/repro/Repro.exe

F# Interactive for F# 4.0 (private)
Freely distributed under the Apache 2.0 Open Source License

For help type #help;;

> [Loading C:\PROJ\FSharp.Compiler.Service_585\myscript.fsx]
TEST_OUTPUT
(Choice1Of2 null, [||])

Actual behavior

Starting Target: RunRepro (==> BuildRepro)
bin/repro/Repro.exe

F# Interactive for F# 4.0 (private)
Freely distributed under the Apache 2.0 Open Source License

For help type #help;;

> [Loading C:\PROJ\FSharp.Compiler.Service_585\myscript.fsx]
Stopped due to error
(Choice2Of2
   System.Exception: Operation could not be completed due to earlier error,
 [|C:\PROJ\FSharp.Compiler.Service_585\myscript.fsx (2,1)-(2,83) parse error The type provider 'C:\PROJ\FSharp.Compiler.Service_585\bin\repro\FSharp.Data.dll' reported an error: Assembly attribute 'TypeProviderAssemblyAttribute' refers to a designer assembly 'FSharp.Data.DesignTime' which cannot be loaded or doesn't exist. Could not load file or assembly 'file:///C:\PROJ\FSharp.Compiler.Service_585\bin\repro\FSharp.Data.DesignTime.dll' or one of its dependencies. The system cannot find the file specified.;
   C:\PROJ\FSharp.Compiler.Service_585\myscript.fsx (2,1)-(2,83) parse warning Referenced assembly 'C:\PROJ\FSharp.Compiler.Service_585\bin\repro\FSharp.Data.dll' has assembly level attribute 'Microsoft.FSharp.Core.CompilerServices.TypeProviderAssemblyAttribute' but no public type provider classes were found|])

Known workarounds

  • Bundling the type provider design assembly should work
  • Removing the reference in Repro to LibraryUsingTypeprovider seems to work as well (matthid/fcs_bug_585@a36921b).

Related information

  • Windows 10
  • FSharp.Compiler.Service 3.0.0.0 Release (2.0.0.6 has same behavior)
  • .NET Runtime 4.6
  • VS 2015

I couldn't reproduce this with the fsi -> When running the failing code within fsi everything seems to work as expected.

--- Initial Report

In fsprojects/FAKE#1274 I noticed that design assemblies of type providers seem to be required, even for indirect references, even when the code trying to compile is not using the type provider at all.

Is this by design or a bug? If it is a bug I can try to create a repro for it. Shouldn't the F# compiler only request the design-assembly when it's needed (lazily)?

I'm not sure if this happens with the regular compiler as well (it probably isn't as much of a problem there as with nuget we have the design assemblies available, even for indirect dependencies), but for now this was detected by using FSharp.Compiler.Service.

@dsyme
Copy link
Contributor

dsyme commented Jun 18, 2016

Could you follow https://github.com/fsharp/FSharp.Compiler.Service/blob/master/ISSUE_TEMPLATE.md and submit a standalone repro with expected/actual steps please.

Thanks!
Don

@matthid
Copy link
Contributor Author

matthid commented Jun 18, 2016

Yeah sure, but I think this isn't easy to reproduce. So when anyone can quickly say if this sounds like a bug or not, it would save me quite some time ... Should the design assembly be needed when the code to compile doesn't use the type provider directly (for example via indirect dependencies)? If yes there is no point reproducing this.

Thanks for your fast answer.

@matthid
Copy link
Contributor Author

matthid commented Jun 18, 2016

Updated the first comment with repro steps.

@matthid matthid changed the title Type Providers design assembly required without direct reference? Type Providers design assembly required without direct reference. Jun 18, 2016
@dsyme dsyme added the bug label Jun 26, 2016
dsyme added a commit to dsyme/FSharp.Compiler.Service that referenced this issue Jul 16, 2016
@dsyme dsyme closed this as completed Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants