Repository navigation
Description
Build info
.net8.0.400-preview.0.24312.1(runtime-8.0.5) sdk
Steps:
1.install net8 preview 4 sdk
2.Quickly run the following command. (Direct Paste)
dotnet new sln -o s1
cd s1
dotnet new console -o a
dotnet new classlib -o b -f netstandard2.1
dotnet new classlib -o c
dotnet sln add a\a.csproj
dotnet sln add b\b.csproj
dotnet sln add c\c.csproj
cd a
dotnet add reference ..\b\b.csproj
dotnet add reference ..\c\c.csproj
Expected Result:
The command runs successfully without returning any errors.
Actual Result:
Get "Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt." When running the command quickly.

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
at Microsoft.VisualStudio.Setup.Configuration.IEnumSetupInstances.Next(Int32, Microsoft.VisualStudio.Setup.Configuration.ISetupInstance[], Int32 ByRef)
--------------------------------
at Microsoft.DotNet.Workloads.Workload.VisualStudioWorkloads.GetVisualStudioInstances()
at Microsoft.DotNet.Workloads.Workload.VisualStudioWorkloads.GetInstalledWorkloads(Microsoft.NET.Sdk.WorkloadManifestReader.IWorkloadResolver, Microsoft.DotNet.Workloads.Workload.List.InstalledWorkloadsCollection, System.Nullable`1<Microsoft.NET.Sdk.WorkloadManifestReader.SdkFeatureBand>)
at Microsoft.DotNet.Workloads.Workload.List.WorkloadInfoHelper.AddInstalledVsWorkloads(System.Collections.Generic.IEnumerable`1<Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadId>)
at Microsoft.DotNet.Workloads.Workload.List.WorkloadInfoHelper.get_InstalledAndExtendedWorkloads()
at Microsoft.DotNet.Tools.New.WorkloadsInfoProvider.GetInstalledWorkloadsAsync(System.Threading.CancellationToken)
at Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory+WorkloadConstraint+<ExtractWorkloadInfoAsync>d__9.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory+WorkloadConstraint+<ExtractWorkloadInfoAsync>d__9, Microsoft.TemplateEngine.Edge, Version=8.0.400.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]](<ExtractWorkloadInfoAsync>d__9 ByRef)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.ValueTuple`2[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Start[[Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory+WorkloadConstraint+<ExtractWorkloadInfoAsync>d__9, Microsoft.TemplateEngine.Edge, Version=8.0.400.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]](<ExtractWorkloadInfoAsync>d__9 ByRef)
at Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory+WorkloadConstraint.ExtractWorkloadInfoAsync(System.Collections.Generic.IEnumerable`1<Microsoft.TemplateEngine.Abstractions.Components.IWorkloadsInfoProvider>, Microsoft.Extensions.Logging.ILogger, System.Threading.CancellationToken)
at Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory+WorkloadConstraint+<CreateAsync>d__6.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory+WorkloadConstraint+<CreateAsync>d__6, Microsoft.TemplateEngine.Edge, Version=8.0.400.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]](<CreateAsync>d__6 ByRef)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Start[[Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory+WorkloadConstraint+<CreateAsync>d__6, Microsoft.TemplateEngine.Edge, Version=8.0.400.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]](<CreateAsync>d__6 ByRef)
at Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory+WorkloadConstraint.CreateAsync(Microsoft.TemplateEngine.Abstractions.IEngineEnvironmentSettings, Microsoft.TemplateEngine.Abstractions.Constraints.ITemplateConstraintFactory, System.Threading.CancellationToken)
at Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory+<Microsoft-TemplateEngine-Abstractions-Constraints-ITemplateConstraintFactory-CreateTemplateConstraintAsync>d__5.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory+<Microsoft-TemplateEngine-Abstractions-Constraints-ITemplateConstraintFactory-CreateTemplateConstraintAsync>d__5, Microsoft.TemplateEngine.Edge, Version=8.0.400.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]](<Microsoft-TemplateEngine-Abstractions-Constraints-ITemplateConstraintFactory-CreateTemplateConstraintAsync>d__5 ByRef)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Start[[Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory+<Microsoft-TemplateEngine-Abstractions-Constraints-ITemplateConstraintFactory-CreateTemplateConstraintAsync>d__5, Microsoft.TemplateEngine.Edge, Version=8.0.400.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]](<Microsoft-TemplateEngine-Abstractions-Constraints-ITemplateConstraintFactory-CreateTemplateConstraintAsync>d__5 ByRef)
at Microsoft.TemplateEngine.Edge.Constraints.WorkloadConstraintFactory.Microsoft.TemplateEngine.Abstractions.Constraints.ITemplateConstraintFactory.CreateTemplateConstraintAsync(Microsoft.TemplateEngine.Abstractions.IEngineEnvironmentSettings, System.Threading.CancellationToken)
at System.Threading.Tasks.Task`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].InnerInvoke()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
dotnet --info
``` dotnet --info C:\Users\v-ainigao>dotnet --info .NET SDK: Version: 8.0.400-preview.0.24312.1 Commit: f13e0daa5c Workload version: 8.0.400-manifests.c1c70047 MSBuild version: 17.11.0-preview-24310-01+74e23a98dRuntime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-arm64
Base Path: C:\Program Files\dotnet\sdk\8.0.400-preview.0.24312.1\
.NET workloads installed:
Configured to use loose manifests when installing new manifests.
[wasm-tools]
Installation Source: SDK 8.0.400-preview.0
Manifest Version: 8.0.5/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.workload.mono.toolchain.current\8.0.5\WorkloadManifest.json
Install Type: FileBased
Host:
Version: 8.0.5
Architecture: arm64
Commit: 087e15321b
.NET SDKs installed:
8.0.400-preview.0.24312.1 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
</details>
Activity
v-ainigao commentedon Jun 14, 2024
After joining other people's accounts, try 6 times and can reproduce.
This issue also repro's on .net9preview6 daily build.
v-ainigao commentedon Jun 17, 2024
This issue also repro's on .net9.0.100-preview.6.24314.10SDK

v-ainigao commentedon Jul 2, 2024
This issue also repro's on .net9.0.100-preview.6.24328.19SDK and I found it seems to be easier to reproduce in an environment with VS+SDK.


dotnet --info
Forgind commentedon Jul 16, 2024
I tried this with today's 9.0 preview on an x64 machine and couldn't reproduce this. I suspect it's ARM64-specific.
marcpopMSFT commentedon Jul 16, 2024
This might be related to the same parallelism issue we found in the template engine with the Aspire template initially. They were able to workaround it but we never found the underlying issue.
@v-ainigao does this only repro on arm64? What version of VS are you using?
v-ainigao commentedon Jul 17, 2024
Yes, only repro on ARM64 and the vs I use is for daily testing main branch.
v-ainigao commentedon Jul 30, 2024
This issue also repro's on latest .net9preview7SDK

build info: vs17.12.0 preview 1.0 [35129.218.mian]+.net9.0.100-preview.7.24379.15(runtime-9.0.0-preview.7.24376.15)
v-ainigao commentedon Aug 7, 2024
This issue also repro's on net9.0.100-rc.1.24406.16SDK.

Environmental Information: Version 17.12.0 preview 2.0 [35206.223.main] + .net9.0.100-rc.1.24406.16SDK.
16 remaining items
marcpopMSFT commentedon Oct 22, 2024
If you're running
newin automation, that might explain why you are more likely to hit this issue. CC @dsplaisted @nagilson @baronfel as we're going to try to make a change to 9.0.2xx that should improve one specific known case of this but I don't think that would help in your case as the fix is narrowly focused on aspire templates.Did reducing your usage of new help with the reliability here? @baronfel any thoughts on why new might be slow? Is it the restore step needing to hit the network a second time or potentially something else?
baronfel commentedon Oct 22, 2024
I don't know much about the perf characteristics of dotnet new - we've mostly been focused on functionality in the past. We probably owe a perf trace to find hot spots. It does do an automatic restore as a post action (which should be able to be skipped IIRC).
gasparnagy commentedon Oct 23, 2024
@marcpopMSFT For the first look it did. But I could not fully finish that because of some side-effects my workaround caused and I haven't yet got time to investigate those. But I will send an update when things are more visible.
gasparnagy commentedon Oct 23, 2024
@baronfel My suspicion is that most of the performance problems rooting from the restore post-action, but I don't have evidence for that. Nevertheless the option of skipping this restore would definitely be helpful, because we anyway add new packages to the created project and do a build afterwards, so the restore has to be run anyway so I don't think we get too much benefit of the restore during
new.If you are interested in performance results, you can download the test result TRX file of our test execution, where you will see the different commands with a time stamp in the test std out. For example in our latest build they are here: https://github.com/reqnroll/Reqnroll/actions/runs/11369395224/artifacts/2064457469
dsplaisted commentedon Oct 23, 2024
I believe most or all of the templates have a
--no-restoreoption which will skip the restore operation when the template is created.gasparnagy commentedon Oct 25, 2024
@dsplaisted Wow! Thank you! This is cool and I did not know about that. Indeed the
classlibtemplate we use has this, I have tested. I was checking thedotnet newdocumentation here, but that did not contain this and I did not think that the individual templates might have options that change the behavior of thedotnet newprocess. But now I see that it is actually documented at the templates, like for classlib here.Thanks for the hint. Really useful. I will give it a quick try.
dsplaisted commentedon Oct 25, 2024
FYI @baronfel, looks like the
--no-restoreoption isn't very discoverable because it is in the options for each template, not in the overalldotnet newhelp.baronfel commentedon Oct 25, 2024
We have very explicit control over the help output for top-level
dotnet new- it would be pretty straightforward to make a help section for "common template options".gasparnagy commentedon Nov 5, 2024
Feedback on performance: I did some basic measurements, and it seems that using
--no-restorefornew classlibimproves it by approx. 60%, which is great.jaredpar commentedon Nov 7, 2024
Reactivating as I was able to reproduce this issue and get a crash dump of
dotnet new.https://github.com/jaredpar/complog/actions/runs/11713633968
Crash Dump Artifact
The core bug seems to be that Microsoft.VisualStudio.Setup.Configuration.Native is not thread safe but the
dotnet newcommand is calling into it from multiple threads. The AV is happening in a native method that is doing a lazy init in roughly the following fashion:This is not safe to call from multiple threads as the assignment can race with
.emptyand lead to an AV. In the crash dump you can see that the AV is happening in the assignment and there is another thread that is calling throughGetVisualStudioInstanceswhich also calls into this codeCrashing frame:
Other thread accessing this same data:
dsplaisted commentedon Nov 7, 2024
Based on the stack trace, it looks like this is caused by the same parallelism issue as dotnet/templating#7946
Work around concurrency issue in COM API