[PR #110] [MERGED] Fix NullReferenceException in PhaseEventArgs.Environments (issue #109) #110

Closed
opened 2026-02-26 17:44:28 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Corsinvest/cv4pve-autosnap/pull/110
Author: @franklupo
Created: 12/23/2025
Status: Merged
Merged: 12/23/2025
Merged by: @franklupo

Base: masterHead: fix/issue-109-null-reference-environments


📝 Commits (1)

  • cf7e5cc Fix NullReferenceException in PhaseEventArgs.Environments property

📊 Changes

6 files changed (+14 additions, -4 deletions)

View changed files

📝 Directory.Build.props (+1 -1)
📝 hooks/template.bat (+0 -0)
📝 hooks/template.ps1 (+0 -0)
📝 hooks/template.sh (+0 -0)
hooks/wrapper-powershell.bat (+10 -0)
📝 src/Corsinvest.ProxmoxVE.AutoSnap.Api/PhaseEventArgs.cs (+3 -3)

📄 Description

Summary

Fixed bug #109 that caused a NullReferenceException when accessing the Environments property of PhaseEventArgs during job-level events.

Problem

The crash occurred when the Environments property attempted to access properties of the Vm object (VmId, Name, Type), but the Vm parameter was null during the following events:

  • SnapJobStart
  • SnapJobEnd
  • CleanJobStart
  • CleanJobEnd

Solution

  • Added null-conditional operator (?.) for Vm property accesses
  • Used null-coalescing operator (??) for Vm.Name to ensure non-null string value
  • Environment variables now safely handle null Vm instances

Additional Changes

  • Renamed hook templates for better clarity: hook-template.*template.*
  • Added PowerShell wrapper for hook execution on Windows (wrapper-powershell.bat)
  • Updated version to 1.18.0

Testing

Hook scripts now work correctly even for job-start/job-end phases where VM is null, preventing the crash.

Fixes #109


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Corsinvest/cv4pve-autosnap/pull/110 **Author:** [@franklupo](https://github.com/franklupo) **Created:** 12/23/2025 **Status:** ✅ Merged **Merged:** 12/23/2025 **Merged by:** [@franklupo](https://github.com/franklupo) **Base:** `master` ← **Head:** `fix/issue-109-null-reference-environments` --- ### 📝 Commits (1) - [`cf7e5cc`](https://github.com/Corsinvest/cv4pve-autosnap/commit/cf7e5ccd122baf22568cfd3e22691f1f49fc3954) Fix NullReferenceException in PhaseEventArgs.Environments property ### 📊 Changes **6 files changed** (+14 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `Directory.Build.props` (+1 -1) 📝 `hooks/template.bat` (+0 -0) 📝 `hooks/template.ps1` (+0 -0) 📝 `hooks/template.sh` (+0 -0) ➕ `hooks/wrapper-powershell.bat` (+10 -0) 📝 `src/Corsinvest.ProxmoxVE.AutoSnap.Api/PhaseEventArgs.cs` (+3 -3) </details> ### 📄 Description ## Summary Fixed bug #109 that caused a `NullReferenceException` when accessing the `Environments` property of `PhaseEventArgs` during job-level events. ## Problem The crash occurred when the `Environments` property attempted to access properties of the `Vm` object (VmId, Name, Type), but the `Vm` parameter was `null` during the following events: - `SnapJobStart` - `SnapJobEnd` - `CleanJobStart` - `CleanJobEnd` ## Solution - Added null-conditional operator (`?.`) for `Vm` property accesses - Used null-coalescing operator (`??`) for `Vm.Name` to ensure non-null string value - Environment variables now safely handle null `Vm` instances ## Additional Changes - Renamed hook templates for better clarity: `hook-template.*` → `template.*` - Added PowerShell wrapper for hook execution on Windows (`wrapper-powershell.bat`) - Updated version to 1.18.0 ## Testing Hook scripts now work correctly even for job-start/job-end phases where VM is null, preventing the crash. Fixes #109 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-26 17:44:28 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/cv4pve-autosnap#110
No description provided.