Build fails when trace string is in a variable

Apr 6, 2011 at 9:12 AM

Hi,

When changing

EtwTrace.Trace("Hello World!");

To

string msg = "Hello World!";

  EtwTrace.Trace(msg);

Build fails with 

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: The "EtwTrace" task failed unexpectedly.

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object.

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at NTrace.NTraceAstVisitor.CreateTraceCall(ParametrizedNode parent, PreprocessorContext context, Int32 line, IList`1 args, Byte level, Int32 flag)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at NTrace.NTraceAstVisitor.ProcessTraceCall(ParametrizedNode parent, PreprocessorContext context, Statement statement, InvocationExpression invocationExpression)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at NTrace.NTraceAstVisitor.VisitExpressionStatement(ExpressionStatement expressionStatement, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Ast.ExpressionStatement.AcceptVisitor(IAstVisitor visitor, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Ast.AbstractNode.AcceptChildren(IAstVisitor visitor, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Visitors.AbstractAstVisitor.VisitBlockStatement(BlockStatement blockStatement, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Ast.BlockStatement.AcceptVisitor(IAstVisitor visitor, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Visitors.AbstractAstVisitor.VisitMethodDeclaration(MethodDeclaration methodDeclaration, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Ast.MethodDeclaration.AcceptVisitor(IAstVisitor visitor, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Ast.AbstractNode.AcceptChildren(IAstVisitor visitor, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Visitors.AbstractAstVisitor.VisitTypeDeclaration(TypeDeclaration typeDeclaration, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at NTrace.NTraceAstVisitor.VisitTypeDeclaration(TypeDeclaration typeDeclaration, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Ast.TypeDeclaration.AcceptVisitor(IAstVisitor visitor, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Ast.AbstractNode.AcceptChildren(IAstVisitor visitor, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Visitors.AbstractAstVisitor.VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Ast.NamespaceDeclaration.AcceptVisitor(IAstVisitor visitor, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Ast.AbstractNode.AcceptChildren(IAstVisitor visitor, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Visitors.AbstractAstVisitor.VisitCompilationUnit(CompilationUnit compilationUnit, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at ICSharpCode.NRefactory.Ast.CompilationUnit.AcceptVisitor(IAstVisitor visitor, Object data)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at NTrace.FileProcessor.Process(String codeFile)

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at NTrace.Tasks.EtwTrace.Execute()

C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018:    at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)Done building project "NTraceTest.csproj" -- FAILED.

Changing the code a bit to

string msg = "Hello World!";

EtwTrace.Trace("{0}",msg);

solves the issue, but it looks somewhat ugly.

Is this a known issue?

Thanks,

--Eran

Coordinator
Apr 6, 2011 at 12:00 PM

This is a known issue; the use pattern for NTrace is similar to that of TraceWpp: format string + args. I believe we added an overload to handle your above usage in the next version, though.

On Apr 6, 2011 5:13 AM, "eranhare" <notifications@codeplex.com> wrote:
> From: eranhare
>
> Hi,When changingEtwTrace.Trace("Hello World!");Tostring msg = "Hello World!"; EtwTrace.Trace(msg);Build fails with C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: The "EtwTrace" task failed unexpectedly.C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object.C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at NTrace.NTraceAstVisitor.CreateTraceCall(ParametrizedNode parent, PreprocessorContext context, Int32 line, IList`1 args, Byte level, Int32 flag)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at NTrace.NTraceAstVisitor.ProcessTraceCall(ParametrizedNode parent, PreprocessorContext context, Statement statement, InvocationExpression invocationExpression)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at NTrace.NTraceAstVisitor.VisitExpressionStatement(ExpressionStatement expressionStatement, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Ast.ExpressionStatement.AcceptVisitor(IAstVisitor visitor, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Ast.AbstractNode.AcceptChildren(IAstVisitor visitor, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Visitors.AbstractAstVisitor.VisitBlockStatement(BlockStatement blockStatement, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Ast.BlockStatement.AcceptVisitor(IAstVisitor visitor, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Visitors.AbstractAstVisitor.VisitMethodDeclaration(MethodDeclaration methodDeclaration, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Ast.MethodDeclaration.AcceptVisitor(IAstVisitor visitor, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Ast.AbstractNode.AcceptChildren(IAstVisitor visitor, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Visitors.AbstractAstVisitor.VisitTypeDeclaration(TypeDeclaration typeDeclaration, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at NTrace.NTraceAstVisitor.VisitTypeDeclaration(TypeDeclaration typeDeclaration, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Ast.TypeDeclaration.AcceptVisitor(IAstVisitor visitor, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Ast.AbstractNode.AcceptChildren(IAstVisitor visitor, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Visitors.AbstractAstVisitor.VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Ast.NamespaceDeclaration.AcceptVisitor(IAstVisitor visitor, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Ast.AbstractNode.AcceptChildren(IAstVisitor visitor, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Visitors.AbstractAstVisitor.VisitCompilationUnit(CompilationUnit compilationUnit, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at ICSharpCode.NRefactory.Ast.CompilationUnit.AcceptVisitor(IAstVisitor visitor, Object data)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at NTrace.FileProcessor.Process(String codeFile)C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at NTrace.Tasks.EtwTrace.Execute()C:\Program Files\MSBuild\NTrace\v1.1\NTrace.CSharp.targets(56,5): error MSB4018: at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)Done building project "NTraceTest.csproj" -- FAILED.Changing the code a bit tostring msg = "Hello World!";EtwTrace.Trace("{0}",msg);solves the issue, but it looks somewhat ugly.Is this a known issue?Thanks,--Eran
>
>
Apr 6, 2011 at 12:42 PM

Thanks