realvizu / NsDepCop

NsDepCop is a static code analysis tool that helps to enforce namespace dependency rules in C# projects. No more unplanned or unnoticed dependencies in your system.
GNU General Public License v2.0
200 stars 32 forks source link

MissingMethodException: MetadataReader.GetBlobContent #25

Closed realvizu closed 7 years ago

realvizu commented 7 years ago

Exception in NsDepCopTask:

System.MissingMethodException: „System.Collections.Immutable.ImmutableArray`1 System.Reflection.Metadata.MetadataReader.GetBlobContent(System.Reflection.Metadata.BlobHandle)”. at: Microsoft.CodeAnalysis.MetadataReaderExtensions.CreateAssemblyIdentityOrThrow(MetadataReader reader, Version version, AssemblyFlags flags, BlobHandle publicKey, StringHandle name, StringHandle culture, Boolean isReference) ...

Microsoft (R) Build Engine version 15.1.1012.6693 Happens only when msbuild runs in parallel mode (/m).

Checked the loaded modules in VS debugger and the correct version of System.Reflection.Metadata is loaded (1.2.1.0, 4.6.24816.1) and the GetBlobContent method is definitely not missing.

realvizu commented 7 years ago

It turned out that it had nothing to do with running msbuild in parallel mode but some other msbuild task was loaded into the AppDomain that interfered with the assembly binding redirection implementation in NsDepCopTask. Changing NsDepCopTask to AppDomainIsolatedTask fixed the problem but at a cost of performance :(