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

Assemblies with generic attributes applied to their assembly cannot be referenced #6734

Closed
davidwrighton opened this issue Aug 4, 2021 · 1 comment · Fixed by #6735
Closed

Comments

@davidwrighton
Copy link
Member

Issue Description

With the new C# feature Generic Attributes (dotnet/roslyn#55190) assemblies can be produced which cannot be referenced via standard msbuild references.

Steps to Reproduce

Using the not yet available C# compiler from Roslyn build a binary with an assembly level attribute which is generic, or sync the dotnet/runtime testbed as of 8/4/2021 and build test src/tests/reflection/GenericAttribute/GenericAttributeTests.csproj (I am about to checkin a change which will workaround the issue)

Note, I was unable to figure out how trigger this failure outside of the runtime build environment, and I was unsuccessful at building a standalone repro using a pre-built IL component.

Expected Behavior

Application builds successfully.

Actual Behavior

Build fails with the following stack trace.

Microsoft (R) Build Engine version 17.0.0-preview-21329-01+1b7661f36 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  GenericAttributeMetadata -> c:\git\runtime\artifacts\tests\coreclr\windows.x64.Debug\reflection\GenericAttribute\GenericAttributeMetadata\GenericAttributeMetadata.dll
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018: The "ResolveAssemblyReference" task failed unexpectedly. [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018: System.InvalidCastException: Specified cast is not valid. [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at System.Reflection.Throw.InvalidCast() in System.Reflection.Metadata.dll:token 0x600009f+0x5 [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at System.Reflection.Metadata.TypeReferenceHandle.op_Explicit(EntityHandle handle) in System.Reflection.Metadata.dll:token 0x60003a9+0xe [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.AssemblyInformation.CorePopulateMetadata() in Microsoft.Build.Tasks.Core.dll:token 0x600013f+0x13a [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.AssemblyInformation.get_Dependencies() in Microsoft.Build.Tasks.Core.dll:token 0x6000138+0x1c [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.AssemblyDependency.AssemblyMetadata..ctor(String path) in Microsoft.Build.Tasks.Core.dll:token 0x6000d22+0xd [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.AssemblyInformation.<>c.<GetAssemblyMetadata>b__12_0(String p) in Microsoft.Build.Tasks.Core.dll:token 0x600106d+0x0 [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) in System.Collections.Concurrent.dll:token 0x60000d3+0x4f [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.AssemblyInformation.GetAssemblyMetadata(String path, ConcurrentDictionary`2 assemblyMetadataCache, AssemblyNameExtension[]& dependencies, String[]& scatterFiles, FrameworkName& frameworkName) in Microsoft.Build.Tasks.Core.dll:token 0x600013b+0x21 [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.SystemState.GetAssemblyMetadata(String path, ConcurrentDictionary`2 assemblyMetadataCache, AssemblyNameExtension[]& dependencies, String[]& scatterFiles, FrameworkName& frameworkName) in Microsoft.Build.Tasks.Core.dll:token 0x60008d0+0x10 [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.ReferenceTable.GetUnifiedAssemblyMetadata(Reference reference, IEnumerable`1& unifiedDependencies, String[]& scatterFiles) in Microsoft.Build.Tasks.Core.dll:token 0x60001fa+0x17 [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.ReferenceTable.FindDependenciesAndScatterFiles(Reference reference, List`1 newEntries) in Microsoft.Build.Tasks.Core.dll:token 0x60001fc+0x3a [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.ReferenceTable.FindAssociatedFiles() in Microsoft.Build.Tasks.Core.dll:token 0x6000208+0xea [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.ReferenceTable.ComputeClosure() in Microsoft.Build.Tasks.Core.dll:token 0x6000207+0xa [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.ReferenceTable.ComputeClosure(IEnumerable`1 remappedAssembliesValue, ITaskItem[] referenceAssemblyFiles, ITaskItem[] referenceAssemblyNames, List`1 exceptions) in Microsoft.Build.Tasks.Core.dll:token 0x6000206+0x38 [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute(FileExists fileExists, DirectoryExists directoryExists, GetDirectories getDirectories, GetAssemblyName getAssemblyName, GetAssemblyMetadata getAssemblyMetadata, GetLastWriteTime getLastWriteTime, GetAssemblyRuntimeVersion getRuntimeVersion, GetAssemblyPathInGac getAssemblyPathInGac, IsWinMDFile isWinMDFile, ReadMachineTypeFromPEHeader readMachineTypeFromPEHeader) in Microsoft.Build.Tasks.Core.dll:token 0x60002b4+0x50f [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute() in Microsoft.Build.Tasks.Core.dll:token 0x60002c5+0x9f [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() in Microsoft.Build.dll:token 0x60015fc+0x3e [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(2203,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) in Microsoft.Build.dll:token 0x600147b+0x2b5 [c:\git\runtime\src\tests\reflection\GenericAttribute\GenericAttributeTests.csproj]

Analysis

The CorePopulateMetadata function assumes that the parent of a custom attribute on an assembly is a TypeReference. This is not a reliable assumption if the type is generic.

Versions & Configurations

I can find evidence that this failure has been in the product for some years, but it hadn't been surfaced to the msbuild team until I tried to fix issue dotnet/runtime#56492

@davidwrighton
Copy link
Member Author

I've put together the above PR, but as I was unable to validate it, I'm not sure what the next steps here are.

davidwrighton added a commit to davidwrighton/runtime that referenced this issue Aug 5, 2021
- Generic attributes need to force the actual exact method to be loaded not just the canonical scenario
- GenericAttribute testing had been disabled due to dotnet/msbuild#6734
- Move GenericAttribute test project to Pri0 as its the only generic custom attribute runtime testing that will occur before .NET 6.0 ships
@benvillalobos benvillalobos removed the needs-triage Have yet to determine what bucket this goes in. label Aug 5, 2021
davidwrighton added a commit to dotnet/runtime that referenced this issue Aug 5, 2021
* Fix CustomAttributeData in the presence of generic attributes
- Generic attributes need to force the actual exact method to be loaded not just the canonical scenario
- GenericAttribute testing had been disabled due to dotnet/msbuild#6734
- Move GenericAttribute test project to Pri0 as its the only generic custom attribute runtime testing that will occur before .NET 6.0 ships
- Test disabled on Mono as Mono currently doesn't support this feature.

Fixes #56492
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants