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

Notification

Icon
Error

ArgumentOutOfRangeException when using shared link global usings
DrDelete
#1 Posted : Thursday, November 2, 2023 2:48:05 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/2/2023(UTC)
Posts: 3
Location: Netherlands

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Hi,

We have a large solution where we put our global usings in 2 seperate files:

- GlobalUsings.Solution.cs
- GlobalUsings.Tests.cs

We attach these two global usings files using a Directory.Build.props file:

(part of the Directory.Build.props file)

<ItemGroup>
<Compile Include="$(SolutionDir)\GlobalUsings.Solution.cs" Link="GlobalUsings.Solution.cs" />
</ItemGroup>

<ItemGroup Condition="$(AssemblyName.Contains('UnitTest'))
OR $(AssemblyName.Contains('Specifications'))
">
<Compile Include="$(SolutionDir)\GlobalUsings.Tests.cs" Link="GlobalUsings.Tests.cs" />
</ItemGroup>

When enabling NCrunch, we encounter a load failing project having this exception:


System.Exception: An exception was thrown in the remote environment: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --> System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter: lenght
at System.String.Substring(Int32 startIndex, Int32 length)
at nCrunch.Compiler.BuildXml.AddTargetScript(String targetName, String dependsOnTargerts, String targetScript)


Notice that I have enabled LongPathEnabled in the registry, and I also re-allocated the workspace dir to :
c:\dev\NCrunch
Remco
#2 Posted : Thursday, November 2, 2023 11:24:55 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 961 times
Was thanked: 1291 time(s) in 1197 post(s)
Hi, thanks for sharing this issue.

Could you check whether the project files involved each have a correct closing tag in the form of: </Project> ?

This error seems to be related to the tag not being found or perhaps being syntactically different.
1 user thanked Remco for this useful post.
DrDelete on 11/3/2023(UTC)
DrDelete
#3 Posted : Friday, November 3, 2023 5:39:55 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/2/2023(UTC)
Posts: 3
Location: Netherlands

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Remco;16917 wrote:
Hi, thanks for sharing this issue.

Could you check whether the project files involved each have a correct closing tag in the form of: </Project> ?

This error seems to be related to the tag not being found or perhaps being syntactically different.


Wooww... that was the issue, thanks!

Our failing project had this:

<Project Sdk="Microsoft.NET.Sdk"/>

It now loads correctly with this content:

<Project Sdk="Microsoft.NET.Sdk">
</Project>


Question: Why did my inital .csproj content not work ? (without the closing tag)

Second question/request: I didn't manage to copy the whole exception stacktrace content from the Trace Output window (I typed the exception stacktrace in first post word for word...), can this be fixed ? I could select all content, but CTRL+C or a copy context menu was not possible...
Remco
#4 Posted : Friday, November 3, 2023 6:12:26 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 961 times
Was thanked: 1291 time(s) in 1197 post(s)
DrDelete;16918 wrote:

Question: Why did my inital .csproj content not work ? (without the closing tag)


NCrunch does some limited parsing of the project file when modifying it to include a few extra things to adjust MSBuild behaviour. It's a bit tacky, but we've found this to be the fastest and most effective way to get what we want from MSBuild.

The way we conduct this differs from how MSBuild loads the project file, so it's possible for us to explode on certain things that MSBuild might tolerate (and vice versa). If enough people get hit with this problem, we can make an effort to improve the experience a bit.

DrDelete;16918 wrote:

Second question/request: I didn't manage to copy the whole exception stacktrace content from the Trace Output window (I typed the exception stacktrace in first post word for word...), can this be fixed ? I could select all content, but CTRL+C or a copy context menu was not possible...


There have been reports of this issue. I've yet to find a way to reproduce it. I think there is something intermittently failing with the copy operation. Can you get it to fail consistently? Does it work for you in some situations and fail in others? I'd like to fix this one.
DrDelete
#5 Posted : Friday, November 3, 2023 6:22:26 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/2/2023(UTC)
Posts: 3
Location: Netherlands

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Remco;16919 wrote:
DrDelete;16918 wrote:

Question: Why did my inital .csproj content not work ? (without the closing tag)


NCrunch does some limited parsing of the project file when modifying it to include a few extra things to adjust MSBuild behaviour. It's a bit tacky, but we've found this to be the fastest and most effective way to get what we want from MSBuild.

The way we conduct this differs from how MSBuild loads the project file, so it's possible for us to explode on certain things that MSBuild might tolerate (and vice versa). If enough people get hit with this problem, we can make an effort to improve the experience a bit.

DrDelete;16918 wrote:

Second question/request: I didn't manage to copy the whole exception stacktrace content from the Trace Output window (I typed the exception stacktrace in first post word for word...), can this be fixed ? I could select all content, but CTRL+C or a copy context menu was not possible...


There have been reports of this issue. I've yet to find a way to reproduce it. I think there is something intermittently failing with the copy operation. Can you get it to fail consistently? Does it work for you in some situations and fail in others? I'd like to fix this one.


-> we can manage this issue by using a closing tag, so not a big deal at the moment

-> you might reproduce this copy/paste issue by creaing a small project in .net7 having no closing tag ;-)
1 user thanked DrDelete for this useful post.
Remco on 11/3/2023(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.046 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download