Skip to content

Operation is not valid due to the current state of the object #405

@zivkan

Description

@zivkan

I'm trying to migrate NuGet.Client from ILMerge to ILRepack. Two of the three projects we ilmerge work well with ilrepack, but the third one is failing in Mono.Cecil

System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at Mono.Cecil.ImportGenericContext.TypeParameter(String type, Int32 position) in /_/Mono.Cecil/Import.cs:line 103
   at Mono.Cecil.DefaultMetadataImporter.ImportTypeSpecification(TypeReference type, ImportGenericContext context) in /_/Mono.Cecil/Import.cs:line 684
   at Mono.Cecil.DefaultMetadataImporter.ImportType(TypeReference type, ImportGenericContext context) in /_/Mono.Cecil/Import.cs:line 548
   at Mono.Cecil.DefaultMetadataImporter.ImportTypeSpecification(TypeReference type, ImportGenericContext context) in /_/Mono.Cecil/Import.cs:line 679
   at Mono.Cecil.DefaultMetadataImporter.ImportType(TypeReference type, ImportGenericContext context) in /_/Mono.Cecil/Import.cs:line 548
   at Mono.Cecil.DefaultMetadataImporter.ImportField(FieldReference field, ImportGenericContext context) in /_/Mono.Cecil/Import.cs:line 700
   at Mono.Cecil.DefaultMetadataImporter.ImportReference(FieldReference field, IGenericParameterProvider context) in /_/Mono.Cecil/Import.cs:line 778
   at ILRepacking.RepackImporter.CloneTo(MethodBody body, MethodDefinition parent)
   at ILRepacking.RepackImporter.CloneTo(MethodDefinition meth, TypeDefinition type, Boolean typeJustCreated) in /_/ILRepack/RepackImporter.cs:line 464
   at ILRepacking.RepackImporter.Import(TypeDefinition type, Collection`1 col, Boolean internalize) in /_/ILRepack/RepackImporter.cs:line 223
   at ILRepacking.RepackImporter.Import(TypeDefinition type, Collection`1 col, Boolean internalize) in /_/ILRepack/RepackImporter.cs:line 206
   at ILRepacking.Steps.TypesRepackStep.RepackTypes() in /_/ILRepack/Steps/TypesRepackStep.cs:line 76
   at ILRepacking.Steps.TypesRepackStep.Perform() in /_/ILRepack/Steps/TypesRepackStep.cs:line 55
   at ILRepacking.ILRepack.RepackCore(String tempOutputDirectory) in /_/ILRepack/ILRepack.cs:line 434
   at ILRepacking.ILRepack.Repack() in /_/ILRepack/ILRepack.cs:line 295
   at ILRepacking.Application.Main(String[] args) in /_/ILRepack/Application.cs:line 50

repro steps:

git clone https://github.com/NuGet/NuGet.Client
cd NuGet.Client
git switch dev-zivkan-ilrepack-error
dotnet build .\src\NuGet.Core\NuGet.Build.Tasks.Pack\

ILRepack logs are available in artifacts\NuGet.Build.Tasks.Pack\bin\Debug\netstandard2.0\ilmergeIlMergeLog.txt

CLI arguments

/out:C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\ilmerge\NuGet.Build.Tasks.Pack.dll /targetplatform:v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.7.2 /allowDup /lib:C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish /internalize /xmldocs /log:C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\ilmergeIlMergeLog.txt /delaysign /keyfile:C:\src\NuGet.Client\dev\build..\keys\35MSSharedLib1024.snk C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\NuGet.Build.Tasks.Pack.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\Microsoft.Bcl.AsyncInterfaces.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\Microsoft.Extensions.FileProviders.Abstractions.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\Microsoft.Extensions.FileSystemGlobbing.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\Microsoft.Extensions.Primitives.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\Newtonsoft.Json.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\NuGet.Commands.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\NuGet.Common.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\NuGet.Configuration.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\NuGet.Credentials.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\NuGet.DependencyResolver.Core.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\NuGet.Frameworks.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\NuGet.LibraryModel.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\NuGet.Packaging.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\NuGet.ProjectModel.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\NuGet.Protocol.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\NuGet.Versioning.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\System.Buffers.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\System.Collections.Immutable.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\System.Memory.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\System.Numerics.Vectors.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\System.Runtime.CompilerServices.Unsafe.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\System.Text.Encodings.Web.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\System.Text.Json.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\System.Threading.Tasks.Extensions.dll C:\src\NuGet.Client\dev\artifacts\NuGet.Build.Tasks.Pack\bin\Debug\net472\publish\System.ValueTuple.dll

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions