Reference preprocessor directive does not support @ verbatim identifier
See original GitHub issueThe 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:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No
#r
isn’t part of the C# spec, it’s part of most C# scripting implementations though, includingcsi.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
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.
Closing as
wont-fix