Skip to content

FS1099 when instantiating internal delegate from another assembly #2401

Description

@fsoikin

When using a lambda expression to instantiate an internal delegate defined in another assembly (available via InternalsVisibleTo), the compiler issues FS1099: No Invoke methods found for delegate type.

Repro steps

a.cs:

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("b")]
namespace Repro {
internal delegate string D( int x );
internal class C { public C( D d ) {} }
}

b.fs:

module ReproFS
let c = new Repro.C( fun x -> "" )

compile:

> csc a.cs /out:a.dll /target:library
> fsc b.fs --out:b.dll --target:library -r:a.dll

Expected behavior

Successful compilation.

Actual behavior

b.fs(2,20): error FS1099: No Invoke methods found for delegate type

Known workarounds

  1. Specifying the delegate type explicitly works: new Repro.C( Repro.D(fun x -> "") )
  2. If the delegate is itself defined in F# (i.e. type D = delegate of int -> string), the error is different: FS0002: This function takes too many arguments, or is used in a context where a function is not expected (though this doesn't have to do with it being internal).
  3. And of course, making the delegate public removes the issue.

Related information

  • Operating system: Windows
  • Branch: Compiler installed, not built locally. Microsoft (R) F# Compiler version 14.0.23413.0
  • .NET Runtime, CoreCLR or Mono Version: .NET Framework 4.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions