gaelcolas / Sampler

Module template with build pipeline and examples, including DSC elements.
MIT License
167 stars 42 forks source link

WARNING: Impossible to extract the name of the Mof based DSCResource, see the error : Failed to import classes from file #402

Closed raandree closed 1 year ago

raandree commented 1 year ago

Problem description

When using Sampler for DSC Resource modules, there may be quite a few warnings like this:

Impossible to extract the name of the Mof based DSCResource, see the error : Failed to import classes from file D:\DscConfig.Demo\output\Module\DscConfig.Demo\0.8.1\DSCResources\EnvironmentVariables\EnvironmentVariables.psd1. Error System.Management.Automation.PSInvalidOperationException: Cim deserializer threw an error when deserializing file C:\Users\randr\AppData\Local\Temp\DscMofHelper_3339712a-5307-44f3-bf12-ade1e0241d97.tmp. ---> Microsoft.Management.Infrastructure.CimException: Syntax Error. Number value is not valid: empty number string                                                                                                                                                                                             At line:1, char:0                                                                                                                                                                                                                                     Buffer:                                                                                                                                                                                                                                              ^@{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

   at Microsoft.Management.Infrastructure.Serialization.CimMofDeserializer.DeserializeClassHandle(Byte[] serializedData, UInt32& offset, IEnumerable`1 cimClasses, String computerName, String namespaceName, OnClassNeeded onClassNeededCallback, GetIncludedFileContent getIncludedFileCallback)
   at Microsoft.Management.Infrastructure.Serialization.CimMofDeserializer.DeserializeClasses(Byte[] serializedData, UInt32& offset, IEnumerable`1 classes, String computerName, String namespaceName, OnClassNeeded onClassNeededCallback, GetIncludedFileContent getIncludedFileCallback)
   at Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser.ParseSchemaMof(String filePath)
   --- End of inner exception stack trace ---
   at Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser.ParseSchemaMof(String filePath)
   at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.ImportClasses(String path, Tuple`2 moduleInfo, Collection`1 errors, Boolean importInBoxResourcesImplicitly)
Build succeeded with warnings. 16 tasks, 0 errors, 1 warnings 00:00:21.9753594

Verbose logs

===============================================================================
                        BUILD DSCRESOURCESTOEXPORT MODULEBUILDER

-------------------------------------------------------------------------------
  /./build/Build_Module_ModuleBuilder/Build_DscResourcesToExport_ModuleBuilder
  D:\DscConfig.Demo\output\RequiredModules\Sampler\0.116.0\tasks\Build-Module.ModuleBuilder.build.ps1:327

        Project Name               = 'DscConfig.Demo'
        Source Path                = 'D:\DscConfig.Demo\source'
        Output Directory           = 'D:\DscConfig.Demo\output'
        Release Notes path         = 'D:\DscConfig.Demo\output\ReleaseNotes.md'
        Built Module Subdirectory  = 'D:\DscConfig.Demo\output\Module'
        Module Manifest Path (src) = 'D:\DscConfig.Demo\source\DscConfig.Demo.psd1'
        Versioned Output Directory = 'True'
        Built Module Manifest      = 'D:\DscConfig.Demo\output\Module\DscConfig.Demo\0.8.1\DscConfig.Demo.psd1'
        Built Module Base          = 'D:\DscConfig.Demo\output\Module\DscConfig.Demo\0.8.1'
        Module Version             = '0.8.1-preview0002'
        Module Version Folder      = '0.8.1'
        Pre-release Tag            = 'preview0002'
        Built Module Root Script   = 'D:\DscConfig.Demo\output\Module\DscConfig.Demo\0.8.1\DscConfig.Demo.psm1'

VERBOSE: Loading module from path 'D:\DscConfig.Demo\output\RequiredModules\ModuleBuilder\2.0.0\ModuleBuilder.psd1'.
WARNING: The names of some imported commands from the module 'ModuleBuilder' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose        
parameter. For a list of approved verbs, type Get-Verb.
VERBOSE: The 'Build-Module' command in the ModuleBuilder' module was imported, but because its name does not include an approved verb, it might be difficult to find. The suggested alternative verbs are "New".
VERBOSE: Importing function 'Build-Module'.
VERBOSE: Importing function 'Convert-CodeCoverage'.
VERBOSE: Importing function 'Convert-LineNumber'.
VERBOSE: Importing alias 'build'.
        Built DSC Resource Path  = 'D:\DscConfig.Demo\output\Module\DscConfig.Demo\0.8.1\DSCResources'
Looking in D:\DscConfig.Demo\output\Module\DscConfig.Demo\0.8.1\DscConfig.Demo.psm1
Looking in D:\DscConfig.Demo\output\Module\DscConfig.Demo\0.8.1\DSCResources
WARNING: Impossible to extract the name of the Mof based DSCResource, see the error : Failed to import classes from file D:\DscConfig.Demo\output\Module\DscConfig.Demo\0.8.1\DSCResources\EnvironmentVariables\EnvironmentVariables.psd1. Error 
System.Management.Automation.PSInvalidOperationException: Cim deserializer threw an error when deserializing file C:\Users\randr\AppData\Local\Temp\DscMofHelper_7b56b1b1-72f1-4b50-95ca-ccb2fdc3470e.tmp. --->
Microsoft.Management.Infrastructure.CimException: Syntax Error. Number value is not valid: empty number string
 At line:1, char:0
 Buffer:
^@{

   at Microsoft.Management.Infrastructure.Serialization.CimMofDeserializer.DeserializeClassHandle(Byte[] serializedData, UInt32& offset, IEnumerable`1 cimClasses, String computerName, String namespaceName, OnClassNeeded onClassNeededCallback,    
GetIncludedFileContent getIncludedFileCallback)
   at Microsoft.Management.Infrastructure.Serialization.CimMofDeserializer.DeserializeClasses(Byte[] serializedData, UInt32& offset, IEnumerable`1 classes, String computerName, String namespaceName, OnClassNeeded onClassNeededCallback,
GetIncludedFileContent getIncludedFileCallback)
   at Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser.ParseSchemaMof(String filePath)
   --- End of inner exception stack trace ---
   at Microsoft.PowerShell.DesiredStateConfiguration.CimDSCParser.ParseSchemaMof(String filePath)
   at Microsoft.PowerShell.DesiredStateConfiguration.Internal.DscClassCache.ImportClasses(String path, Tuple`2 moduleInfo, Collection`1 errors, Boolean importInBoxResourcesImplicitly)
Done /./build/Build_Module_ModuleBuilder/Build_DscResourcesToExport_ModuleBuilder 00:00:00.0626132
Done /./build/Build_Module_ModuleBuilder 00:00:00.6163567

===============================================================================
                        BUILD NESTEDMODULES MODULEBUILDER

-------------------------------------------------------------------------------
  /./build/Build_NestedModules_ModuleBuilder
  D:\DscConfig.Demo\output\RequiredModules\Sampler\0.116.0\tasks\Build-Module.ModuleBuilder.build.ps1:129

        Project Name               = 'DscConfig.Demo'
        Source Path                = 'D:\DscConfig.Demo\source'
        Output Directory           = 'D:\DscConfig.Demo\output'
        Release Notes path         = 'D:\DscConfig.Demo\output\ReleaseNotes.md'
        Built Module Subdirectory  = 'D:\DscConfig.Demo\output\Module'
        Module Manifest Path (src) = 'D:\DscConfig.Demo\source\DscConfig.Demo.psd1'
        Versioned Output Directory = 'True'
        Built Module Manifest      = 'D:\DscConfig.Demo\output\Module\DscConfig.Demo\0.8.1\DscConfig.Demo.psd1'
        Built Module Base          = 'D:\DscConfig.Demo\output\Module\DscConfig.Demo\0.8.1'
        Module Version             = '0.8.1-preview0002'
        Module Version Folder      = '0.8.1'
        Pre-release Tag            = 'preview0002'
        Built Module Root Script   = 'D:\DscConfig.Demo\output\Module\DscConfig.Demo\0.8.1\DscConfig.Demo.psm1'

VERBOSE: Loading module from path 'D:\DscConfig.Demo\output\RequiredModules\ModuleBuilder\2.0.0\ModuleBuilder.psd1'.
WARNING: The names of some imported commands from the module 'ModuleBuilder' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose        
parameter. For a list of approved verbs, type Get-Verb.
VERBOSE: The 'Build-Module' command in the ModuleBuilder' module was imported, but because its name does not include an approved verb, it might be difficult to find. The suggested alternative verbs are "New".
VERBOSE: Importing function 'Build-Module'.
VERBOSE: Importing function 'Convert-CodeCoverage'.
VERBOSE: Importing function 'Convert-LineNumber'.
VERBOSE: Importing alias 'build'.
Done /./build/Build_NestedModules_ModuleBuilder 00:00:00.0355322

===============================================================================

How to reproduce

Building for example CommonTasks.

Expected behavior

No warning.

Current behavior

See above

Suggested solution

Will follow later.

Operating system the target node is running

Windows, happens with PowerShell 5.1 and 7.3.

PowerShell version and build the target node is running

Windows, happens with PowerShell 5.1 and 7.3.

Module version used

1.116.0
johlju commented 1 year ago

The PR https://github.com/gaelcolas/Sampler/pull/403 looks like it should have solved this. Closing this. Please reopen if this was not the case.