Skip to content

Need better diagnosability if NetstandardAwareAssemblyResolver throws #1196

Closed
@KirillOsenkov

Description

@KirillOsenkov

Our CI is using code coverage on .NET SDK 3.0.100.

When trying to update to SDK to 5.0.301 the instrumentation fails:

C:\Users\kirill\.nuget\packages\coverlet.msbuild\2.6.3\build\coverlet.msbuild.targets(7,5): [coverlet] Unable to instrument module: C:\.....\Release\net472\.......dll because : The type initializer for 'Coverlet.Core.Instrumentation.NetstandardAwareAssemblyResolver' threw an exception. 

From looking at the static constructor, it only catches the FileNotFoundException:

static NetstandardAwareAssemblyResolver()
{
try
{
// To be sure to load information of "real" runtime netstandard implementation
_netStandardAssembly = System.Reflection.Assembly.LoadFile(Path.Combine(Path.GetDirectoryName(typeof(object).Assembly.Location), "netstandard.dll"));
System.Reflection.AssemblyName name = _netStandardAssembly.GetName();
_name = name.Name;
_publicKeyToken = name.GetPublicKeyToken();
_assemblyDefinition = AssemblyDefinition.ReadAssembly(_netStandardAssembly.Location);
}
catch (FileNotFoundException)
{
// netstandard not supported
}
}

I think the Instrumenter should be trying to unwrap the exception before reporting it:

_logger.LogWarning($"Unable to instrument module: '{_module}' because : {ex.Message}");

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementGeneral enhancement request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions