There were definitely some pain points with class-based resources at first, and so far, I still haven’t used them in production. What do you mean by “fails”, though? What error message are you seeing?
VERBOSE: [WIN-8SU88BLP5RK]: LCM: [ Start Resource ] [[Env_Refresh]TESTVAR]
VERBOSE: [WIN-8SU88BLP5RK]: LCM: [ Start Test ] [[Env_Refresh]TESTVAR]
VERBOSE: [WIN-8SU88BLP5RK]: [[Env_Refresh]TESTVAR] Importing the module
Env_Refresh in force mode.
Object reference not set to an instance of an object.
+ CategoryInfo : OperationStopped: (:) [], CimException
+ FullyQualifiedErrorId : System.NullReferenceException
+ PSComputerName : localhost
VERBOSE: [WIN-8SU88BLP5RK]: LCM: [ End Test ] [[Env_Refresh]TESTVAR] in 0.0780 seconds.
The PowerShell DSC resource '[Env_Refresh]TESTVAR' with SourceInfo 'C:\Users\Administrator\AppData\Local\Temp
\kitchen\modules\Env_Refresh\examples\dsc_configuration.ps1::5::9::Env_Refresh' threw one or more
non-terminating errors while running the Test functionality. These errors are logged to the ETW channel
called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
+ CategoryInfo : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : NonTerminatingErrorFromProvider
+ PSComputerName : localhost
VERBOSE: [WIN-8SU88BLP5RK]: LCM: [ End Set ]
The SendConfigurationApply function did not succeed.
+ CategoryInfo : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : MI RESULT 1
+ PSComputerName : localhost
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.176 seconds
[10.111.111.113]: PS C:\Users\Administrator\AppData\Local\Temp\kitchen\modules\Env_Refresh>
It errors less often when I don’t have another configuration entry AFTER my Env_Refresh TESTVAR {…}.
Also added a gif on my repo’s readme:
It took 4 tries before actually raising the error.
I’ve seen some people report that same error on the MVP mailing list as well. If Microsoft has fixed it in the latest Fast Ring builds, great (once that version of PowerShell hits general release on the downlevel operating systems.)
I don’t know if this will help, but in the email thread I’m looking at, they mention that the error was only happening if they had the LCM’s DebugMode set to something other than ‘None’. (ForceModuleImport, etc).
This was spot on, the problem exist only when the Debug mode is set to something else than NONE.
On my Test-Kitchen configuration file .kitchen.yml I had
Changing with debug_mode: None fixed my issue. (or amending the LCM via Set-DscLocalConfigurationManager)
After that I tested on my laptop with the debug_mode: All, and it still worked.
I suspect that bug has been fixed in WMF 5.1 (PSVersion 5.1.14390.0), but confirmation would be great (we may have to wait for WMF5.1 release and its release notes).