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

Fix 'Failed to resolve assembly' cecil issue #625

Merged
merged 10 commits into from
Dec 3, 2019

Conversation

MarcoRossignoli
Copy link
Collaborator

@MarcoRossignoli MarcoRossignoli commented Nov 28, 2019

Closes #560 and improve scenario where we have to use /p:CopyLocalLockFileAssemblies=true

In case of load issue we get

 warning : [coverlet] Unable to instrument module: C:\git\coverletissue\case-service\case-service.Tests\bin\Release\netcoreapp2.2\case-service.dll because : AssemblyResolutionException for 'Microsoft.Extensions.Logging.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Try to add <PreserveCompilationContext>true</PreserveCompilationContext> to test projects </PropertyGroup> or pass '/p:CopyLocalLockFileAssemblies=true' option to the 'dotnet test' command-line

If we add <PreserveCompilationContext> custom load seem to work.


+--------------+--------+--------+--------+
| Module       | Line   | Branch | Method |
+--------------+--------+--------+--------+
| case-service | 52,36% | 56,12% | 41,55% |
+--------------+--------+--------+--------+

+---------+--------+--------+--------+
|         | Line   | Branch | Method |
+---------+--------+--------+--------+
| Total   | 52,36% | 56,12% | 41,55% |
+---------+--------+--------+--------+
| Average | 52,36% | 56,12% | 41,55% |
+---------+--------+--------+--------+

thank's @rpatrick00 for the repro.

I ask to some guys that helped with solution to check if could work @livarcocc @dasMulli @nguerrera @dsplaisted @elinor-fung and @jbevain from which I took some piece of code for resolver.

We need to check if we're on core because we support also .NET Framework.

cc: @tonerdo @petli

private readonly string _modulePath;
// this is lazy because we cannot create AspNetCoreSharedFrameworkResolver if not on .NET Core runtime,
// runtime folders are different
private readonly Lazy<CompositeCompilationAssemblyResolver> _compositeResolver = new Lazy<CompositeCompilationAssemblyResolver>(() => new CompositeCompilationAssemblyResolver(new ICompilationAssemblyResolver[]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here build up composite resolver...so we check on defaults and also on aspnetcore shared folders at the end


using DependencyContextJsonReader contextJsonReader = new DependencyContextJsonReader();
Dictionary<string, Lazy<AssemblyDefinition>> libraries = new Dictionary<string, Lazy<AssemblyDefinition>>();
foreach (string fileName in Directory.GetFiles(Path.GetDirectoryName(_modulePath), "*.deps.json"))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

search and load all deps files and try to resolve

}
catch (AssemblyResolutionException)
{
if (IsDotNetCore())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try manual resolving in case of .net app

}
}

internal class AspNetCoreSharedFrameworkResolver : ICompilationAssemblyResolver
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asp.net core shared framework resolver, search inside folders

/// correct forwards.
/// Check compares 'assembly name' and 'public key token', because versions could differ between runtimes.
/// </summary>
internal class NetstandardAwareAssemblyResolver : DefaultAssemblyResolver
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved in new own file

@MarcoRossignoli MarcoRossignoli added the bug Something isn't working label Nov 28, 2019
@MarcoRossignoli
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MarcoRossignoli
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MarcoRossignoli MarcoRossignoli merged commit 3856c76 into coverlet-coverage:master Dec 3, 2019
@MarcoRossignoli MarcoRossignoli deleted the issue_560 branch December 3, 2019 12:48
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
Development

Successfully merging this pull request may close these issues.

Failed to resolve assembly
1 participant