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

Get a compilation error "CS1009: Unrecognized escape sequence" when using verbatim strings #516

Closed
davkean opened this Issue Aug 3, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@davkean
Member

davkean commented Aug 3, 2017

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Jobs;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

[LegacyJitX64Job]
public class IndexOfAny
{
    private const string File = @"Folder\Bar\Foo\Bar\FooBar.cs";

    [Params(File)]
    public string Input { get; set; }

    [Benchmark(Description = "Hand written loop over array (IndexOfAny)")]
    public void IndexOfAny_HandWrittenLoop()
    {
        for (int i = 0; i < 100000; i++)
        {
            ContainsHelper.IndexOfAny_HandWrittenLoop(Input, s_charsToEscape);
        }
    }

internal class ContainsHelper
{
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static int IndexOfAny_HandWrittenLoop_HardcodedChars(string value)
    {
        for (int i = 0; i < value.Length; i++)
        {
            switch (value[i])
            {
                case '%':
                case '*':
                case '?':
                case '@':
                case '$':
                case '(':
                case ')':
                case ';':
                case '\'':
                    return i;
            }
        }

        return -1;
    }
}

 class Program
{
    static void Main(string[] args)
    {
        BenchmarkDotNet.Running.BenchmarkRunner.Run<IndexOfAny>();
    }
}
// **************************
// Benchmark: IndexOfAny.'Hand written loop over hardcoded chars (ContainsAny)': LegacyJitX64(Jit=LegacyJit, Platform=X64, Runtime=Clr) [Input=Folder\Bar\Foo\Bar\FooBar.cs]
// *** Generate ***
// Result = Success
// BinariesDirectoryPath = C:\Users\davkean\Source\Repos\PathHelpers\PathHelpers\bin\Release

// *** Build ***
BuildScript: C:\Users\davkean\Source\Repos\PathHelpers\PathHelpers\bin\Release\BDN.Generated.bat
CS1009: Unrecognized escape sequenceCS1009: Unrecognized escape sequenceCS1009: Unrecognized escape sequenceCS1009: Unrecognized escape sequence// Result = Failure
@davkean

This comment has been minimized.

Show comment
Hide comment
@davkean

davkean Aug 3, 2017

Member

Hmm, I can't get this to work even if I change the verbatim string to escape sequence.

Member

davkean commented Aug 3, 2017

Hmm, I can't get this to work even if I change the verbatim string to escape sequence.

@AndreyAkinshin

This comment has been minimized.

Show comment
Hide comment
@AndreyAkinshin

AndreyAkinshin Aug 3, 2017

Member

Hey @davkean, thanks for the report. The problem is: we use params values as parts of generated filenames (without escaping, unfortunately). Will fix it soon. For now, I can suggest the following workaround:

private string[] inputNames = new string[] { @"Folder\Bar\Foo\Bar\FooBar.cs" };

[Params(0)]
public int InputIndex;

// Benchmark
var input = inputNames[InputIndex];
Member

AndreyAkinshin commented Aug 3, 2017

Hey @davkean, thanks for the report. The problem is: we use params values as parts of generated filenames (without escaping, unfortunately). Will fix it soon. For now, I can suggest the following workaround:

private string[] inputNames = new string[] { @"Folder\Bar\Foo\Bar\FooBar.cs" };

[Params(0)]
public int InputIndex;

// Benchmark
var input = inputNames[InputIndex];

@AndreyAkinshin AndreyAkinshin added the bug label Aug 3, 2017

@davkean

This comment has been minimized.

Show comment
Hide comment
@davkean

davkean Aug 3, 2017

Member

Thanks for the quick reply and workaround!

Member

davkean commented Aug 3, 2017

Thanks for the quick reply and workaround!

@AndreyAkinshin AndreyAkinshin added this to the v0.10.10 milestone Aug 7, 2017

@AndreyAkinshin

This comment has been minimized.

Show comment
Hide comment
@AndreyAkinshin

AndreyAkinshin Aug 7, 2017

Member

@davkean, I added some escaping magic, the fix will be available in v0.10.10.

Member

AndreyAkinshin commented Aug 7, 2017

@davkean, I added some escaping magic, the fix will be available in v0.10.10.

@davkean

This comment has been minimized.

Show comment
Hide comment
@davkean

davkean Aug 8, 2017

Member

👍

Member

davkean commented Aug 8, 2017

👍

alinasmirnova added a commit to alinasmirnova/BenchmarkDotNet that referenced this issue Sep 22, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment