question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reference preprocessor directive does not support @ verbatim identifier

See original GitHub issue

The following usage of the reference preprocessor directive fails with an ArgumentNullException even though the string is valid C#:

#r @"C:\MyProject\MyAssembly.dll"
Error: System.ArgumentNullException: Value cannot be null. (Parameter 'references[25]')
   at Microsoft.CodeAnalysis.Scripting.ParameterValidationHelpers.AddRangeChecked[T](ArrayBuilder`1 builder, IEnumerable`1 items, String parameterName)
   at Microsoft.CodeAnalysis.Scripting.ParameterValidationHelpers.ConcatChecked[T](ImmutableArray`1 existing, IEnumerable`1 items, String parameterName)
   at Microsoft.CodeAnalysis.Scripting.ScriptOptions.AddReferences(IEnumerable`1 references)
   at Microsoft.CodeAnalysis.Scripting.ScriptOptions.AddReferences(IEnumerable`1 references)
   at Cake.Infrastructure.Scripting.RoslynScriptSession.Execute(Script script) in C:\projects\cake\src\Cake\Infrastructure\Scripting\RoslynScriptSession.cs:line 94
   at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath) in C:\projects\cake\src\Cake.Core\Scripting\ScriptRunner.cs:line 172
   at Cake.Features.Building.BuildFeature.RunCore(IRemainingArguments arguments, BuildFeatureSettings settings) in C:\projects\cake\src\Cake\Features\Building\BuildFeature.cs:line 99
   at Cake.Features.Building.BuildFeature.Run(IRemainingArguments arguments, BuildFeatureSettings settings) in C:\projects\cake\src\Cake\Features\Building\BuildFeature.cs:line 49
   at Cake.Commands.DefaultCommand.Execute(CommandContext context, DefaultCommandSettings settings) in C:\projects\cake\src\Cake\Commands\DefaultCommand.cs:line 72

However, without the @ verbatim identifier, it works even though it’s not really a valid C# string:

#r "C:\MyProject\MyAssembly.dll"

Cake version: 1.0.0-rc0002 (Cake.Tool)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
devleadcommented, Jan 26, 2021

No #r isn’t part of the C# spec, it’s part of most C# scripting implementations though, including csi.exe

We should probably throw a better error, but don’t think we should implement full C# string support, don’t believe even C# preprocessor evaluates standard C# string expressions.

This is what csi.exe reports

#r "C:\MyProject\MyAssembly.dll" no error #r @"C:\MyProject\MyAssembly.dll"

will report

- (1,4): error CS7010: Quoted file name expected

if we add any validation we need to make sure all existing use cases work i.e. GAC assemblies still work which can be referenced by name without extension.

0reactions
augustoproietecommented, Nov 17, 2021

Closing as wont-fix

Read more comments on GitHub >

github_iconTop Results From Across the Web

#if preprocessor directive incorrectly handles enclosed C# ...
Actually, this produces a CS1024 error because the compiler seems to interpret the "# text" portion of the string as a preprocessor directive....
Read more >
The C Preprocessor - GCC, the GNU Compiler Collection
The C preprocessor, often known as cpp, is a macro processor that is used automatically by the C compiler to transform your program...
Read more >
The C Preprocessor
Preprocessing directives are lines in your program that start with `#' . The `#' is followed by an identifier that is the directive...
Read more >
6 Lexical structure - C# language specification
An identifier with an @ prefix is called a verbatim identifier. Note: Use of the @ prefix for identifiers that are not keywords...
Read more >
cpp.info-2
A special feature of ANSI Standard C is that the self-reference is not considered a macro call. It is passed into the preprocessor...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found