Skip to content

System.ArgumentException when publishing trimmed, self-contained app #14873

Description

@whoteit92

Please provide a succinct description of the issue.

Exception in question :
Unhandled exception. System.ArgumentException: The record type 'Program+MyRecord' is invalid. Required constructor is not defined.
at Microsoft.FSharp.Reflection.Impl.getRecordConstructorMethod(Type, BindingFlags) in D:\a_work\1\s\src\FSharp.Core\reflect.fs:line 1011
at Microsoft.FSharp.Reflection.FSharpValue.PreComputeRecordConstructorInfo(Type, FSharpOption`1 ) in D:\a_work\1\s\src\FSharp.Core\reflect.fs:line 1299
at <StartupCode$SelfContainedTest>.$Program.main@()

Only happens when is set to true in a self-contained publish.

Repro steps

Create new F# console app with the following code

type MyRecord = {
    A : string
    B: string
}
let test = Microsoft.FSharp.Reflection.FSharpValue.PreComputeRecordConstructorInfo typeof<MyRecord>
printfn "Done"

Use the following publish profile:

<Project>
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>C:\Users\whoteit\Desktop\New folder</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <_TargetId>Folder</_TargetId>
    <TargetFramework>net7.0</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <SelfContained>true</SelfContained>
    <PublishSingleFile>false</PublishSingleFile>
    <PublishReadyToRun>false</PublishReadyToRun>
    <PublishTrimmed>true</PublishTrimmed>
  </PropertyGroup>
</Project>

If possible attach a zip file with the repro case. This often makes it easier for others to reproduce.
The zip file should ideally represent the situation just before the call/step that is problematic.

Expected behavior

Trimming should not have an effect on the code above.

Actual behavior

System.ArgumentException

Known workarounds
None

Provide a description of any known workarounds.

Related information

Provide any related information (optional):

  • Operating system : Tested on both Windows (x64) and Linux (arm32)
  • .NET Runtime kind (.NET Core, .NET Framework, Mono) : .NET 7
  • Editing Tools (e.g. Visual Studio Version, Visual Studio)

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions