Repository: files-community/Files
File: src/Files.App/Services/Windows/WindowsDialogService.cs (C#)

Code before:
				using ComPtr<IShellItem> pResultShellItem = default;
				pDialog.Get()->GetResult(pResultShellItem.GetAddressOf());
				if (pResultShellItem.Get() == null)
					throw new COMException("FileSaveDialog returned invalid shell item.");
				pResultShellItem.Get()->GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out var lpFilePath);
				filePath = lpFilePath.ToString();

				return true;
			}
			catch (Exception ex)
			{
				App.Logger.LogError(ex, "Failed to open FileOpenDialog.");

				return false;
			}
		}

		/// <inheritdoc/>
		public unsafe bool Open_FileSaveDialog(nint hWnd, bool pickFoldersOnly, string[] filters, Environment.SpecialFolder defaultFolder, out string filePath)
		{
			filePath = string.Empty;

			try
			{
				using ComPtr<IFileSaveDialog> pDialog = default;
				HRESULT hr = pDialog.CoCreateInstance(CLSID.CLSID_FileSaveDialog, null, CLSCTX.CLSCTX_INPROC_SERVER);

				if (filters.Length is not 0 && filters.Length % 2 is 0)
				{
					List<COMDLG_FILTERSPEC> extensions = [];

					for (int i = 1; i < filters.Length; i += 2)
					{
						COMDLG_FILTERSPEC extension;

						extension.pszSpec = (char*)Marshal.StringToHGlobalUni(filters[i]);
						extension.pszName = (char*)Marshal.StringToHGlobalUni(filters[i - 1]);

						// Add to the exclusive extension list
						extensions.Add(extension);
					}

					// Set the file type using the extension list
					pDialog.Get()->SetFileTypes(extensions.ToArray());
				}

				// Get the default shell folder (My Computer)
				using ComPtr<IShellItem> pDefaultFolderShellItem = default;
				fixed (char* pszDefaultFolderPath = Environment.GetFolderPath(defaultFolder))
				{
					hr = PInvoke.SHCreateItemFromParsingName(

Review comment (bug):
```suggestion
				HRESULT hr = pDialog.CoCreateInstance(CLSID.CLSID_FileSaveDialog, null, CLSCTX.CLSCTX_INPROC_SERVER).ThrowOnFailure();
```

Code after:
				using ComPtr<IShellItem> pResultShellItem = default;
				pDialog.Get()->GetResult(pResultShellItem.GetAddressOf());
				if (pResultShellItem.Get() == null)
					throw new COMException("FileSaveDialog returned invalid shell item.");
				pResultShellItem.Get()->GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out var lpFilePath);
				filePath = lpFilePath.ToString();

				return true;
			}
			catch (Exception ex)
			{
				App.Logger.LogError(ex, "Failed to open FileOpenDialog.");

				return false;
			}
		}

		/// <inheritdoc/>
		public unsafe bool Open_FileSaveDialog(nint hWnd, bool pickFoldersOnly, string[] filters, Environment.SpecialFolder defaultFolder, out string filePath)
		{
			filePath = string.Empty;

			try
			{
				using ComPtr<IFileSaveDialog> pDialog = default;
				HRESULT hr = pDialog.CoCreateInstance(CLSID.CLSID_FileSaveDialog, null, CLSCTX.CLSCTX_INPROC_SERVER).ThrowOnFailure();

				if (filters.Length is not 0 && filters.Length % 2 is 0)
				{
					List<COMDLG_FILTERSPEC> extensions = [];

					for (int i = 1; i < filters.Length; i += 2)
					{
						COMDLG_FILTERSPEC extension;

						extension.pszSpec = (char*)Marshal.StringToHGlobalUni(filters[i]);
						extension.pszName = (char*)Marshal.StringToHGlobalUni(filters[i - 1]);

						// Add to the exclusive extension list
						extensions.Add(extension);
					}

					// Set the file type using the extension list
					pDialog.Get()->SetFileTypes(extensions.ToArray());
				}

				// Get the default shell folder (My Computer)
				using ComPtr<IShellItem> pDefaultFolderShellItem = default;
				fixed (char* pszDefaultFolderPath = Environment.GetFolderPath(defaultFolder))
				{
					hr = PInvoke.SHCreateItemFromParsingName(