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

Path is empty for VB My namespace #1073

Merged
merged 15 commits into from Jan 24, 2023

Conversation

daveMueller
Copy link
Collaborator

closes #775

@daveMueller
Copy link
Collaborator Author

The issue is the My namespace in Visual Basic (My). Usually a sequence point has a reference to a source file like this.

grafik

In Visual Basic the compiler injects the My classes into the assembly without a reference to a source file.

grafik

Maybe there are also other scenarios where a sequence point doesn't have a reference to a source file that we haven't encountered yet. So I created a PR that excludes code like this within an assembly.

But I could also think of a solution that really just filters out the My namespace in a Visual Basic assembly. Just let me know what you think.

@MarcoRossignoli MarcoRossignoli changed the title 775 Path is empty Path is empty for VB My namespace Jan 28, 2021
@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Jan 28, 2021

Thx Dave, need to go deeper on it to understand if as you said make sense something for that injected namespace.

Can we add a new VB project and create a test?Is it too complex?
Something like coverlet.tests.projectsample.vbmynamespace here https://github.com/coverlet-coverage/coverlet/tree/master/test

@MarcoRossignoli MarcoRossignoli added bug Something isn't working tenet-reporters Issue related to coverage output files(reporters) labels Jan 28, 2021
@daveMueller
Copy link
Collaborator Author

Can we add a new VB project and create a test?Is it too complex?
Something like coverlet.tests.projectsample.vbmynamespace here https://github.com/coverlet-coverage/coverlet/tree/master/test

I will give it a try.
But nevertheless I think instrumentation of IL code that doesn't have a reference to a source file doesn't make much sense for the coverage.

@MarcoRossignoli
Copy link
Collaborator

But nevertheless I think instrumentation of IL code that doesn't have a reference to a source file doesn't make much sense for the coverage.

I agree...but we need to be pretty sure to not break something, so I'm ok with the update but I'd like to have a test in place for future issue on it.

@@ -597,7 +597,7 @@ public int SampleMethod()
}
else
{
Assert.NotEmpty(result.Documents);
Assert.Empty(result.Documents);
Copy link
Collaborator

Choose a reason for hiding this comment

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

mmm is this correct?(didn't tested on my own but seem we expect opposite behavior)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The compiled assembly in this test doesn't have a reference to a source file an thus the result is always empty. Before my change in the Instrumenter this test returned a result with a empty document source which is exactly what would create the bug in the report generation.

image

After my change such a InstrumenterResult isn't created anymore and that's why now result.Documents is also empty here.

To make this test the way it was intended the dynamically created assembly must contain sequence points with a reference to the source file. But what ever I tried here the assemblies sequence points never had source file information.

var emitResult = compilation.Emit(outputStream, pdbStream, options: isWindows ? emitOptions : emitOptions.WithDebugInformationFormat(DebugInformationFormat.PortablePdb));

The assemblies sequence points were always without source information.

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

got it...pls can you add a comment on top of that assert with this explanation for future reference?

@daveMueller
Copy link
Collaborator Author

daveMueller commented Feb 5, 2021

@MarcoRossignoli It seems the My namespace in VB is only in .NET Framework projects. I think it isn't possible to add a project with .NET Framework as target to the coverlet solution? Or at least I couldn't do it without crashing the build jobs?

@MarcoRossignoli
Copy link
Collaborator

MarcoRossignoli commented Feb 5, 2021

@MarcoRossignoli It seems the My namespace in VB is only in .NET Framework projects. I think it isn't possible to add a project with .NET Framework as target to the coverlet solution? Or at least I couldn't do it without crashing the build jobs?

I think it's possible, AFAIK .NET Framework project can be compiled on all plat through dotnet driver, I have some doubt on type resolution for Mac/Linux but in those case we can skip tests. Give it a try and let me know.

If it'll be too hard to do, we can merge and open a ticket to follow up this.

@daveMueller
Copy link
Collaborator Author

@MarcoRossignoli I'm still working on this but it seems that Linux and Mac build jobs can't build the project. Windows build job is green now. But for the others I'm getting (The reference assemblies for .NETFramework,Version=v4.7.2 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application.)

@daveMueller
Copy link
Collaborator Author

Thanks, but now I get a vbc : error BC2017: could not find library 'Microsoft.VisualBasic.dll' which is weird because the ReferenceAssemblies package contains the dll. Somehow the build doesn't look in the right place? According to the documentation (docs) this should work. Any other ideas? Otherwise I'll open a issue in the dotnet repo.

@MarcoRossignoli
Copy link
Collaborator

Ok Dave open an issue on the dotnet repo, I never used that ref I only know about the existence

@MarcoRossignoli
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@nk111
Copy link

nk111 commented Oct 5, 2021

Hi, I've been trying to get a coverage report for a .Net Framework project displayed in Devops for 3 days. After updating all possible tools on our build agent, the test is finally running via DotNetCli. But unfortunately I also get the "The path is empty" error at the end. It is a VB project.
Can this PR please be completed?

@@ -510,7 +510,12 @@ private void InstrumentType(TypeDefinition type)

private void InstrumentMethod(MethodDefinition method)
{
//_logger.LogInformation($"Instrumenting method '{method.FullName}' in module '{_module}'.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

@daveMueller I see this line as commented, is it on purpose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm pretty sure I just used it for debugging. So no need to keep this in the log.

@MarcoRossignoli
Copy link
Collaborator

@daveMueller do you plan to move on this one or can I take over? It's pretty old and I think we can exclude tests from Mac/Linux and run failing one only on Win.

@daveMueller
Copy link
Collaborator Author

@MarcoRossignoli I totally forgot about this one. I'm currently really busy so I would be glad if you could take over. I'm fine with excluding the test for Mac/Linux. Thank you.

@MarcoRossignoli
Copy link
Collaborator

Great, thanks a lot for the effort here!

daveMueller and others added 5 commits January 18, 2023 00:10
# Conflicts:
#	coverlet.sln
#	src/coverlet.core/Instrumentation/Instrumenter.cs
#	test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs
#	test/coverlet.core.tests/coverlet.core.tests.csproj
# Conflicts:
#	Documentation/Changelog.md
@MarcoRossignoli
Copy link
Collaborator

Is this good to merge now?

@daveMueller
Copy link
Collaborator Author

@MarcoRossignoli yes I worked on it again and made the integration test run on all platforms now. So this is ready for review/merge. I asked in the issue (#775 (comment)) if someone can give it a try.

@MarcoRossignoli MarcoRossignoli merged commit a014bf0 into coverlet-coverage:master Jan 24, 2023
@MarcoRossignoli
Copy link
Collaborator

Thanks @daveMueller

@daveMueller daveMueller deleted the 775_PathIsEmpty branch September 12, 2023 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tenet-reporters Issue related to coverage output files(reporters)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The path is empty. (Parameter 'path')
3 participants