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

'await' cannot be used in an expression containing the type 'System.ReadOnlySpan<char>' #774

Closed
majora2007 opened this issue Dec 4, 2021 · 5 comments · Fixed by #777
Closed
Labels
area: core Issues that address the core abstractions & the wrappers state: ready to pick Issues that are ready for being worked on state: released Issues that are released type: enhancement Issues that propose new functionality

Comments

@majora2007
Copy link

majora2007 commented Dec 4, 2021

Describe the bug
When utilizing System.IO.Abstractions for Path.Join, the following code snippet does not compile on .NET 6, however it does when using System.IO Path.Join.

    var path = System.IO.Abstractions.FileSystem.Path.Join("/config/covers", await GetChapterCoverImageAsync(chapterId));
    public async Task<string> GetChapterCoverImageAsync(int chapterId)
        {
    
            return await _context.Chapter
                .Where(c => c.Id == chapterId)
                .Select(c => c.CoverImage)
                .AsNoTracking()
                .SingleOrDefaultAsync();
        }

public class Chapter {
   public string CoverImage { get; set; }
}

Expected behavior
I expect that the Abstraction works identically to System.IO and it builds and functions correctly.

Additional context
I am using .NET 6 and System.IO.Abstractions 14.0.3

@majora2007 majora2007 added state: needs discussion Issues that need further discussion type: bug Issues that describe misbehaving functionality labels Dec 4, 2021
@fgreinacher
Copy link
Contributor

Thanks for reporting @majora2007! Can you share a self-contained reproduction? A tiny snippet like #713 (comment) is totally fine.

@fgreinacher fgreinacher added the area: core Issues that address the core abstractions & the wrappers label Dec 8, 2021
@majora2007
Copy link
Author

majora2007 commented Dec 8, 2021

@fgreinacher

I just wrote a small .NET 6 program:

Program.cs:

using AbstractionsReproductionTest;

Console.WriteLine("Hello, World!");

var p = await new GetTest().Path();
Console.Write(p);

GetTest

using System.IO.Abstractions.TestingHelpers;

namespace AbstractionsReproductionTest;

public class GetTest
{
    public async Task<string> Path()
    {
        return new MockFileSystem().Path.Join("/config/covers", await GetPath());
    }

    private async Task<string> GetPath()
    {
        return await Task.Run(() => "Hello");
    } 
}

image

@fgreinacher
Copy link
Contributor

Thanks a ton for sharing the repro!

I could reproduce and it seems the root cause is that we're missing the string overloads for Path.Join(), causing overload resolution to pick the ReadOnlySpan<char> overloads as next best candidates.

To fix this we need to add the missing overloads. Happy to accept a PR, otherwise I'll take care in the next couple of days.

@fgreinacher fgreinacher added state: ready to pick Issues that are ready for being worked on type: enhancement Issues that propose new functionality and removed type: bug Issues that describe misbehaving functionality state: needs discussion Issues that need further discussion labels Dec 9, 2021
fgreinacher added a commit that referenced this issue Dec 22, 2021
This adds support for all `System.IO.Path` members in .NET 5 and 6.

BREAKING CHANGE: This is a breaking change for people implementing `System.IO.Abstractions.IPath` or deriving from `System.IO.Abstractions.PathBase` because new members have been added to their API surface.

Fixes #774
@github-actions
Copy link

This is addressed in release v15.0.1.

@github-actions github-actions bot added the state: released Issues that are released label Dec 22, 2021
@foz1284
Copy link

foz1284 commented May 3, 2022

Hi, love the project, it just gave me a headache this afternoon!

The fix doesnt work for .net Core 3.1,

This is no longer a significant issue for me as I have just updated to .net5.0 to workaround the problem but it might occur for others so I thought I should raise an issue:

The fix appears to only apply to FEATURE_PATH_JOIN_WITH_PARAMS which supports the following targets:

Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net5.0'">

I'm having this issue with .net Core 3.1 but you can see from the link below that it should support Join(string path1, string path2)
https://docs.microsoft.com/en-us/dotnet/api/system.io.path.join?view=netcore-3.1#system-io-path-join(system-string-system-string)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues that address the core abstractions & the wrappers state: ready to pick Issues that are ready for being worked on state: released Issues that are released type: enhancement Issues that propose new functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants