Skip to content

Commit

Permalink
[msbuild] Pass a stream to XDocument.Load instead of a path. (#18722)
Browse files Browse the repository at this point in the history
XDocument.Load(string) takes a URI, not a file path. This usually works if
there are no special characters in the file path, but for instance with a path
with a colon (say 'a:b/some/file'), we'll get an exception about invalid uri
scheme.

So instead use the XDocument.Load(Stream) overload, and create the stream
using the file path instead, in which case there's no problem with special
characters.
  • Loading branch information
rolfbjarne authored Aug 15, 2023
1 parent 9a4b5db commit 587f722
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion msbuild/Xamarin.MacDev.Tasks/Tasks/ReadItemsFromFileBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public override bool Execute ()
{
var result = new List<ITaskItem> ();
foreach (var file in File) {
var document = XDocument.Load (file.ItemSpec);
// XDocument.Load(string) takes a string to a URI, not a file path, so with certain characters that becomes a problem.
// Just File.OpenRead instead and use the XDocument.Load(Stream) overload instead.
using var stream = global::System.IO.File.OpenRead (file.ItemSpec);
var document = XDocument.Load (stream);

var items = document.Root
.Elements (ItemGroupElementName)
Expand Down

4 comments on commit 587f722

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.