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

"AnnotatorBuildTask" task failed unexpectedly with Mono.Cecil.AssemblyResolutionException #37

Closed
jnm2 opened this issue Oct 14, 2019 · 5 comments · Fixed by #39
Closed
Labels
bug Something isn't working

Comments

@jnm2
Copy link
Contributor

jnm2 commented Oct 14, 2019

This is alpha 77 on Shouldly's Ubuntu build:

Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]

I'm not sure whether this is recoverable or whether it should just be turned into a nicer error.

Stack trace:

at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.MetadataResolver.Resolve(TypeReference type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleDefinition.Resolve(TypeReference type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.TypeReference.Resolve() [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.Mixin.CheckedResolve(TypeReference self) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeEnum(TypeReference enum_type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeElementValue(TypeReference type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArgument(TypeReference type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeNamedArgument(Collection`1& fields, Collection`1& properties) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.SignatureReader.ReadCustomAttributeNamedArguments(UInt16 count, Collection`1& fields, Collection`1& properties) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.CustomAttribute.<Resolve>b__35_0(CustomAttribute attribute, MetadataReader reader) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleDefinition.Read[TItem](TItem item, Action`2 read) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.CustomAttribute.get_ConstructorArguments() [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.ReadCustomAttributes(ICustomAttributeProvider provider) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.ReadType(TypeDefinition type) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.ReadTypes(Collection`1 types) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.ReadModule(ModuleDefinition module, Boolean resolve_attributes) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.<ReadModule>b__2_0(ModuleDefinition module, MetadataReader reader) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleDefinition.Read[TItem](TItem item, Action`2 read) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ImmediateModuleReader.ReadModule() [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleReader.CreateModule(Image image, ReaderParameters parameters) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleDefinition.ReadModule(Disposable`1 stream, String fileName, ReaderParameters parameters) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at TunnelVisionLabs.ReferenceAssemblyAnnotator.Program.Main(Nullable`1 log, String referenceAssembly, String annotatedReferenceAssembly, String outputAssembly) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at TunnelVisionLabs.ReferenceAssemblyAnnotator.AnnotatorBuildTask.Execute() [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/home/appveyor/projects/shouldly/src/Shouldly/Shouldly.csproj]
@sharwell
Copy link
Member

@jbevain Is there a way we can get Cecil to treat this as an opaque/unresolved error type that is simply preserved when we write the modified assembly back to disk?

@sharwell
Copy link
Member

@jnm2 Worst case, we can make it report a warning like it does for other skipped assemblies. The build author can control whether the warning is treated as a build error.

@sharwell sharwell added bug Something isn't working help wanted Extra attention is needed labels Oct 14, 2019
@jbevain
Copy link

jbevain commented Oct 14, 2019

@sharwell I think this happens because you use the Immediate mode that creates the entire DOM, including custom attributes.

If you use the delayed one, it might be able to optimize the reading/writing of the custom attributes straight to bytes.

What happens here is that Cecil reads a custom attribute with an enum, and there's no way to know the size of the enum unless you resolve its type definition.

@jnm2
Copy link
Contributor Author

jnm2 commented Oct 16, 2019

Interestingly, there are a ton of "Failed to resolve assembly" messages when building an empty net451 project on Windows. These are at the info level rather than the error caused by the uncaught AssemblyResolutionException when building on Ubuntu. I wonder why Cecil on Windows isn't throwing AssemblyResolutionException the same way.

[...]
  Cannot find a matching type for System.Configuration.IriParsingElement
  Failed to resolve assembly: 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
  Cannot find a matching type for System.Configuration.IdnElement
  Failed to resolve assembly: 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
  Cannot find a matching type for System.Net.Mail.SmtpAccess
  Failed to resolve assembly: 'System.Security.Permissions, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
  Cannot find a matching type for System.Net.Mail.SmtpPermissionAttribute
  Failed to resolve assembly: 'System.Security.Permissions, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
  Cannot find a matching type for System.Net.Mail.SmtpPermission
  Failed to resolve assembly: 'System.Security.Permissions, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
  Cannot find a matching type for System.Configuration.SettingsBase
  Failed to resolve assembly: 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
  Cannot find a matching type for System.Configuration.ApplicationSettingsBase
  Failed to resolve assembly: 'System.Configuration.ConfigurationManager, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
[...]

802 failures total: net451 build log.txt

@jnm2
Copy link
Contributor Author

jnm2 commented Oct 16, 2019

That's produced by this code:

try
{
annotatedTypeDefinition = exportedType.Resolve();
}
catch (AssemblyResolutionException e)
{
log?.LogMessage($"Cannot find a matching type for {typeDefinition}");
log?.LogMessage(e.Message);
}

Once ReadingMode.Deferred is used it will be interesting to see if/where we need to add another catch block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants