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

File attachments aren't added if they are prefixed with "\\?\" #1145

Open
dro123 opened this issue Dec 11, 2023 · 4 comments
Open

File attachments aren't added if they are prefixed with "\\?\" #1145

dro123 opened this issue Dec 11, 2023 · 4 comments
Labels

Comments

@dro123
Copy link

dro123 commented Dec 11, 2023

When reporting a bug, please provide the following information to speed up triage:

@OsirisTerje
Copy link
Member

Can you add a small repro for this?

How do you get file paths like that? Is it to circumvent max path length?

@dro123
Copy link
Author

dro123 commented Dec 11, 2023

Yes it's to handle long paths.
It's not an issue nowadays, but when I originally added the code it was an issue and that's why it's still in that format.
I updated my code and removed the \\?\ from there and it works fine now.
I thought I'm probably not the only one and it's probably an easy fix, that's why I reported it :-)

Project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
    <PackageReference Include="NUnit" Version="4.0.1" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
  </ItemGroup>
</Project>

Test code:

using NUnit.Framework;

[TestFixture]
public class Tests
{
    [Test]
    public void LongPathTest()
    {
        TestContext.AddTestAttachment(@"\\?\C:\Temp\test.txt");
        Assert.Fail();
    }
}

Run tests with:
dotnet test

Output:
Ignoring attachment with path '\\?\C:\Temp\test.txt' due to problem with path: Invalid URI: The hostname could not be parsed.

@OsirisTerje
Copy link
Member

Thanks! I'll add that to the test we have, and get this fixed.

@stevenaw
Copy link
Member

stevenaw commented Apr 9, 2024

The next release of the framework, 4.2, should include a change which may help here by avoiding the need to explicitly specify the "\?" prefix: nunit/nunit#4353

Note that that change will still only include the prefix in the output file itself if it is explicitly specified as part of the AddTestAttachment call so this adapter-side issue may still be needed if that's desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants