Error: Collection was modified

Hello,
I’ve just checked latest stable build and found an incompatibility with our projects when opening in VisualStudio 2019 or 2022.
elements Projects are not loaded and there is an error message in the VS Ouput window: error : The element list has changed. The enumeration operation failed to continue.

Ive found that the problem is rooted ath the Property declared: <RestoreAdditionalProjectSources>https://nuget.tescosw.loc/nuget</RestoreAdditionalProjectSources>, when its not present, all looks good: But when building, the project is always skipped (without letting me to know why), ill continue to research on this.

You can easily reproduce the problem by creating the project using the ClassLibrary (Classic .NET) template and adding the prop to.

Elements 11.0.0.2747

Mabye is worth to add that we use this element becase we use a

<Import Project="$(MSBuildExtensionsPath)\RemObjects Software\Elements\RemObjects.Elements.Echoes.**Legacy**.targets" />

in combination with:

 <PackageReference Include="CadToolRefs">
            <ExcludeAssets>runtime</ExcludeAssets>
            <PrivateAssets>contentfiles;analyzers</PrivateAssets>
        </PackageReference>

and that was the only way how to make this combination work. Now the error reported blocks this usage.

If i migrated to

<Import Project="$(MSBuildExtensionsPath)\RemObjects Software\Elements\RemObjects.Elements.Echoes.targets" />

<NuGetReference Include="BimToolRefs:*">
	<ExcludeAssets>runtime</ExcludeAssets>
    <PrivateAssets>contentfiles;analyzers</PrivateAssets>
     <NuGetRepository>https://nuget.tescosw.loc/nuget</NuGetRepository>
            <Private>True</Private>
</NuGetReference>
<NuGetReference Include="CadToolRefs:*">
	<ExcludeAssets>runtime</ExcludeAssets>
    <PrivateAssets>contentfiles;analyzers</PrivateAssets>
    <NuGetRepository>https://nuget.tescosw.loc/nuget</NuGetRepository>
    <Private>True</Private>
</NuGetReference>

Then i get this:

Exception processing package reference BimToolRefs : NuGet 2.x and lower repositories are not supported at this stage. Please upgrade to NuGet 3.0 or later. ClassLibrary6 C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\RemObjects Software\Elements\RemObjects.Elements.Echoes.targets

And then, when i change the Repository URL to file:/// protocol

<NuGetReference>
      <ExcludeAssets>runtime</ExcludeAssets>
      <PrivateAssets>contentfiles;analyzers</PrivateAssets>
      <NuGetRepository>file:///C:/inetpub/wwwroot/nuget_server/Packages/</NuGetRepository>
      <Private>True</Private>
  </NuGetReference>

Then the reference appears as resolved but still i get this error E46: Unknown identifier “Tesco”

There ClassLibrary5.zip - Google Drive is a simplified project with the nugets, please check this and give me an advice how to make the PackageReference work as it used to work.
Just adjust the nuget repo path to the Packages directory present in the archive.

Curious. This is as far as I know ow not a project setting we support/use (but we do migrate it when importing/converting .vcproj and .vbproj files). I’ll log an issue for the VS team.

If you drop the setting and instead add a new entry in ProjectItems:

<NuGetRepository>https://nuget.tescosw.loc/nuget</NuGetRepository>

does the same error occur? If not, that is not just a workaround, but actually the proper way to specify custom NuGet repositories.

Logged as bugs://E25963.

And the other interesting thing is that our nuget server is created from this Using NuGet.Server to Host NuGet Feeds | Microsoft Docs

And it tells about itself a version 3.4.1. so it should be supported if the version matches the api version and according to the documentation it should.

So what is wrong here ?

That leads me to the web api version insufficiency problem or with file protocol another problom, ive
reported this in next post probably while you were just writing an answer to me.

Ah sorry, I missed the second message. Indeed we do not support NuGet versions below 3. The previous error just hid this from you, I’d not that changing over to <NuGetRepository> causes it.

Hard to say. Could/can I access this server for testing? As I recall, NuGet 2 vs NuGet 3+ are vastly different protocols, and we simply never implemented the older one (and have no plans to, at this stage). could it be that while your server uses a version that supportsd N uGet 3.4, it is set to serve using the old protocol? Beyond that, I don’t know, as I don’t have any personal experience with hosting own NuGet servers…

If I can test against your server, ic an confirm if it is indeed serving v2, or if something else is going wrong (which is quite possible of course).

Checking the code, we expect a json document at the server’s root that contains a { Resources: { RegistrationsBaseUrl = "..." entry, to determine if the server is NuGet 3.

About the migration: there is also a strange beavior when this file
grafikaOriginal.elements (16.0 KB)
gets converted to this file when opened in solution
grafikaAfterConversion.elements (14.1 KB)

Hmm. I don’t believe we ever convert/save project files to drop all readability and whitespace, as has happened here — whether in Water, VS for using the EBUild conversion tools. It makes kit very hard to compare and look for the/any “problem” with this fie (although the XML should be valid even if not well-readable).

What are the steps for this conversion? And what is the concrete problem you have with the second version (aside form it not looking nice)?

The project opens fine for me, and after a re-save, it looks mostly identical to the old one, except for some (expected) cleanup, and the migrated NuGetRepository tag…

Logged as bugs://E25964.

For me: just opening the original file in the VsS2022 solution is enough to get the converted file.

There is a problem after the conversion that only one PackageReference is converted:

From my side it looks like this content:

<PackageReference Include="BimToolRefs" Version="1.0.5">
	<ExcludeAssets>runtime</ExcludeAssets>
    <PrivateAssets>contentfiles;analyzers</PrivateAssets>
</PackageReference>
<PackageReference Include="CadToolRefs" Version="1.0.5">
	<ExcludeAssets>runtime</ExcludeAssets>
    <PrivateAssets>contentfiles;analyzers</PrivateAssets>
</PackageReference>

leads to this content + the inapropriate formatting.

  <NuGetReference Include="BimToolRefs" />
        <PackageReference Include="CadToolRefs" Version="1.0.5">
            <ExcludeAssets>runtime</ExcludeAssets>
            <PrivateAssets>contentfiles;analyzers</PrivateAssets>
        </PackageReference>

Curious, it looks like something fails mid-convert. We’ll see if we can reproduce this. Might be all three related.

Might be correct, dont know, i barely understand the nuget api. Anyway, we have no way for upgrade the api than push to nuget.org publicly.

Unrelated, this project uses RemObjects.Elements.Echoes.Legacy.targets so it should not be using EBuild and the new NuGet support at all, as Legacy projects continue to build using MSBuild…

I think it is related, in every post i declare the Import version. Im avare of the differences.
The main problem now is that the project with Legacy.targets cannost be opened in VS due the Error thrown.

The problem with the incorrect projectFileMigration is a problem becasue it happens even with the legacy.targets import, where PackageReference is OK.

The other issue, nuget API version 2 not supported is aparantly problem at our side, but it is combined only with non-legacy targets.

Okay, cool. that is being looked at.

Yes, this would apply only to projects using EBuild.

bugs://E25964 was closed as fixed.

And how is the bugs://E25963 going ? Thanks.

Still open. but I’ll chase it up with the team.

Hello, could you please provide me with a project that you cannot open in VS2022 with Collection modified exception. The attached here ClassLibrary5.zip is probably the project after conversion and does not show the problem.
Thanks in advance.