dotnet / dotnet/msbuild

XmlPeek throws non-specific exception on empty-string result with item output

Open
#3,399 0 comments 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

### Steps to reproduce
Have the `XmlPeek` task query XML such that at least one result will be a zero-length string. Include an `Output` element that uses the `ItemName` attribute.

Project file (`repro.proj`)
```xml


<DriftReport xmlns="http://schemas.microsoft.com/sqlserver/dac/DriftReport/2012/02">
<Additions>
<Object Name="" Parent="[db_owner]" Type="SqlRoleMembership" />
<Object Name="[foo\foo]" Parent="" Type="SqlUser" />
</Additions>
<Removals />
<Modifications />
</DriftReport>



<_DriftChangeType Include="Additions">
dummy value

<_DriftChangeType Include="Removals;Modifications">
SqlForeignKeyConstraint





```

Directory contents:
```
/
- repro.proj
```

Command line:
```
msbuild repro.proj /v:diag
```

### Expected behavior
`XmlPeek` throws exception with text pointing to the root cause, e.g.
> C:\foo\repro.proj(27,7): error MSBXXXX: The "XmlPeek" task results included one or more zero length strings. "_DriftAdditions" parameter "Include" cannot have zero length.

### Actual behavior
`XmlPeek` throws an exception with text that makes it difficult to infer the root cause.

> Using "XmlPeek" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
> Task "XmlPeek" (TaskId:2)
> Task Parameter:XmlContent=<DriftReport xmlns="http://schemas.microsoft.com/sqlserver/dac/DriftReport/2012/02">
> <Additions>
> <Object Name="" Parent="[db_owner]" Type="SqlRoleMembership" />
> <Object Name="[foo\foo]" Parent="" Type="SqlUser" />
> </Additions>
> <Removals />
> <Modifications />
> </DriftReport> (TaskId:2)
> Task Parameter:Namespaces= (TaskId:2)
> Task Parameter:Query=/dr:DriftReport/dr:Additions/*[local-name()='Object' and not(@Type='dummy value')]/@Name (TaskId:2)
> Found "". (TaskId:2)
> Found "[foo\foo]". (TaskId:2)
> C:\foo\repro.proj(27,7): **error MSB4028: The "XmlPeek" task's outputs could not be retrieved from the "Result" parameter. Parameter "includeEscaped" cannot have zero length.**
> Done executing task "XmlPeek" -- FAILED. (TaskId:2)

### Environment data
`msbuild /version` output:

> Microsoft (R) Build Engine version 15.7.179.6572 for .NET Framework
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> 15.7.179.6572

### Key line from MSBuild source
`XmlPeek.Execute()` adds an invalid `Item`, with empty string as its `Identity`/`Include` value:
https://github.com/Microsoft/msbuild/blob/9ed9a33898750567e1ac653174038e542158cf02/src/Tasks/XmlPeek.cs#L247

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.