microsoft / PTVS

Python Tools for Visual Studio
https://aka.ms/PTVS
Apache License 2.0
2.53k stars 676 forks source link

Opening VS solution leads to error #8075

Open KerstinKeller opened 6 days ago

KerstinKeller commented 6 days ago

Describe the bug I get the below error message when loading a bigger solution file, that contains both C++ and Python projects. It's a CMake based project and all project files are generated from within CMake. When I closed the project the other night, everything was working ok

Expected behavior Opening VS without exception / error, being able to debug the Python project.

Additional context and screenshots

[Window Title]
devenv.exe

[Main Instruction]
An unexpected error occurred

[Content]
Please press Ctrl+C to copy the contents of this dialog and report this error to our issue tracker.

[^] Hide details  [Schließen]

[Expanded Information]
Build: 16.11.21196.2

System.ArgumentException: Falscher Parameter. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
   at EnvDTE.ConfigurationManager.get_ActiveConfiguration()
   at Microsoft.PythonTools.Project.PythonProjectNode.SetCurrentConfiguration()
   at Microsoft.VisualStudioTools.Project.ProjectNode.GetMsBuildProperty(String propertyName, Boolean resetCache)
   at Microsoft.VisualStudioTools.Project.ProjectNode.GetProjectProperty(String propertyName, Boolean resetCache)
   at Microsoft.PythonTools.Project.CondaEnvCreateProjectInfoBar.<CheckAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PythonTools.Project.PythonProjectNode.<TriggerInfoBarsAsync>d__107.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PythonTools.Infrastructure.VSTaskExtensions.<HandleAllExceptions>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

Error on Debug

Image

Configuration information (If you are providing a diagnostics file (see below), skip this section) VS Version: Version 16.11.41 PTVS version: 16.11.21196.2 Python version: 3.12.0 Debugger Type (if applicable): [New debugger or legacy debugger?]

Diagnostics file I was not able to locate a diagnostics file in the Temp Directory

One last note: To me, there is no apparent reason as to when I am able to debug when launching a pyproj. Sometimes it works, sometimes it doesn't. Sometimes I need to restart Visual Studio. It would be very helpful if the the displayed dialog contained more information on why launching is not possible.

KerstinKeller commented 6 days ago

It also seems to be related to the pyproj Files themselves. Take the following:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == 'RelWithDebInfo' ">
    </Configuration>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>ed257ab2-033d-3b6e-9c0e-9ee5d38d9d8c</ProjectGuid>
    <ProjectHome>.</ProjectHome>
    <StartupFile>D:/github/project/lang/python/samples/core/service/file.py</StartupFile>
    <SearchPath>..\..\..\..\bin\RelWithDebInfo\python</SearchPath>
    <WorkingDirectory>.</WorkingDirectory>
    <OutputPath>.</OutputPath>
    <Name>py_minimal_service_client</Name>
    <RootNamespace>py_minimal_service_client</RootNamespace>
    <InterpreterId>MSBuild|debugging-env|$(MSBuildProjectFullPath)</InterpreterId>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
    <DebugSymbols>true</DebugSymbols>
    <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'RelWithDebInfo' ">
    <DebugSymbols>true</DebugSymbols>
    <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <DebugSymbols>true</DebugSymbols>
    <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="D:/github/project/lang/python/samples/core/service/file.py" />
  </ItemGroup>
  <ItemGroup>
    <Interpreter Include="C:/Users/xxx/AppData/Local/Programs/Python/Python312">
      <Id>debugging-env</Id>
      <Version>0.0</Version>
      <Description>Debugging Environment (Python 3.12.0 )</Description>
      <InterpreterPath>C:/Users/xxx/AppData/Local/Programs/Python/Python312/python.exe</InterpreterPath>
      <WindowsInterpreterPath>C:/Users/xxx/AppData/Local/Programs/Python/Python312/python.exe</WindowsInterpreterPath>
      <PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
      <Architecture>X64</Architecture>
    </Interpreter>
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
  <!-- Uncomment the CoreCompile target to enable the Build command in
       Visual Studio and specify your pre- and post-build commands in
       the BeforeBuild and AfterBuild targets below. -->
  <!--<Target Name="CoreCompile" />-->
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
</Project>

The files are generated like this, because I want to be able to debug the RelWithDebInfo builds, for C++ extensions which are build with nanobind. Especially the first property group seems to cause problems sometimes, when I change

    <Configuration Condition=" '$(Configuration)' == 'RelWithDebInfo' ">

to

    <Configuration Condition=" '$(Configuration)' == 'Release' ">

there is a higher chance that I can actually use the debugger.