Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

FromRelativePath throws if path is contained in quotes
abelb
#1 Posted : Monday, September 25, 2017 5:33:37 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
The following exception is thrown if a relative path is contained in quotes:

Code:
[19:23:02.7842-Core-29] Event [SettingValueChangedEvent:LogVerbosity] is being processed on Core thread with subscriber: CoreLogger.
ENGINE - [19:23:11.6937-InitialisationQueueTask-32] ERROR (Load): Error occurred during load of component at D:\Projects\OpenSource\VisualFSharp\tests\fsharpqa\testenv\src\ILComparer\ILComparer.fsproj: System.Exception: An exception was thrown in the remote environment: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: An error occurred while trying to parse the file Path '"D:\Projects\OpenSource\VisualFSharp\tests\fsharpqa\testenv\src\ILComparer\..\..\..\..\..\src\fsharp\msft.pubkey"' as relative to 'D:\Projects\OpenSource\VisualFSharp\tests\fsharpqa\testenv\src\ILComparer'.  Ensure the file path is valid and does not exceed the maximum length of 259 characters
   at nCrunch.Common.IO.FilePath.FromRelativePath(String relativeFilePath, DirectoryPath relativeTo)
   at nCrunch.Common.IO.FilePath.FromAbsoluteOrRelativePath(String absoluteOrRelativePath, DirectoryPath relativeTo)
   at nCrunch.Compiler.RemoteBuildRunner.(String , DirectoryPath )
   at nCrunch.Compiler.RemoteBuildRunner.AnalyseComponentBuild(ComponentLoadParameters parameters)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at nCrunch.TaskRunner.Ipc.IpcMessageProcessor.(CallMethodMessage )
   at nCrunch.TaskRunner.Ipc.IpcMessageProcessor.ProcessMessageReturningResult(Byte[] data)
   at nCrunch.TaskRunner.Ipc.RemoteInstance.(Byte[] )
   at nCrunch.TaskRunner.Ipc.RemoteInstance.Invoke(IMessage msg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at nCrunch.Compiler.IRemoteBuildRunner.AnalyseComponentBuild(ComponentLoadParameters parameters)
   at nCrunch.Core.BuildManagement.BuildProcessLauncher..(IRemoteBuildRunner )
   at nCrunch.Core.BuildManagement.BuildProcessLauncher.(Action`1 , FilePath , String , ExternalProcess )
   at nCrunch.Core.BuildManagement.BuildProcessLauncher.(Action`1 , ProcessorArchitecture , GridClientId , BuildSystemParameters , IList`1 )
   at nCrunch.Core.BuildManagement.BuildProcessLauncher.AnalyseComponentBuildInExternalProcess(ComponentLoadParameters parameters, IList`1 customEnvironmentVariables)
   at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.(ProcessorArchitecture , String )
   at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.CreateComponentFromXml(FilePath projectFilePath, ParsedBuildXml projectXml, FilePath solutionFilePath, String[] additionalFilesToIncludeAtSolutionLevel, Boolean isLoadedFromFile, VisualStudioVersion vsVersion, ComponentUniqueName componentName, TaskSettings componentTaskSettings, Exception parseException, String targetFramework)


The workaround is to remove the quotes, however for situations where the path contains spaces, this is not a solution. The cause is an OtherFlags directive in the fsproj file (but just as well applies to csproj files). In the below fragment, FSharpSourcesRoot is set to a path that contains "..\..\", which caused the path-resolver to be called in the first place, I think.

Code:
<OtherFlags>$(OtherFlags) --keyfile:"$(FSharpSourcesRoot)\fsharp\msft.pubkey"</OtherFlags>
.

A probable solution is to remove any single or double (paired) quotes when such a path is found. Note that MSBuild has no problem with this path.
Remco
#2 Posted : Tuesday, September 26, 2017 2:44:04 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,123

Thanks: 957 times
Was thanked: 1286 time(s) in 1193 post(s)
Thanks for sharing this problem.

It doesn't match with my knowledge of MSBuild conventions for an item to be valid when in quotes, so this looks to be special case.

Does suppressing this with a condition allow you to work around the problem? i.e:

<OtherFlags Condition="'$(NCrunch)' != '1'">$(OtherFlags) --keyfile:"$(FSharpSourcesRoot)\fsharp\msft.pubkey"</OtherFlags>
abelb
#3 Posted : Tuesday, September 26, 2017 2:27:26 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 9/12/2014(UTC)
Posts: 155
Location: Netherlands

Thanks: 19 times
Was thanked: 11 time(s) in 11 post(s)
Quote:
so this looks to be special case.

In a way, that is correct. It is under <OtherFlags>, which means it is an extra compiler setting. If you have multiple compiler switches, you need to have the ones that contain a value *and* can contain spaces, inside quotes. This may not be the default for paths in MSBuild files, but commandline compiler settings are past on the command prompt, I believe, and so they need to be quoted. This is true for any project, and may happen just as well in the PostBuild or PreBuild steps, for instance (but I don't know if these are translated too, I don't currently use those steps).

I was actually already happily surprised that NCrunch was smart enough to detect paths in <OtherFlags>.

I'm sure that suppressing it would work, though it would fail the minute the NCrunch run is done from a system that has spaces in the path.

And FWIW, this seems to be part of Windows' way of handling paths, it is not necessarily an MSBuild convention. For instance, this command works:

Code:
cd "bar\..\..\..\test dir"
1 user thanked abelb for this useful post.
Remco on 9/26/2017(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.037 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download