d365collaborative / d365fo.tools

Tools used for Dynamics 365 Finance and Operations
MIT License
246 stars 101 forks source link

Unable to load d365fo.tools in Azure Function #650

Closed Ralph101 closed 1 year ago

Ralph101 commented 2 years ago

hi,

We want to run some d365fo.tools command in our Azure Function environment, but I'm unable to load the module. I have add the module via the requirements.ps1 file. I can see in the -ListAvailable all modules and dependencies are available. But when I run a command I receive module is found but could not load, for more information run Import-Module d365fo.tools. After running this command I receive the following error:

2022-06-03T10:37:03.466 [Error] ERROR: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.Exception             :Type       : System.IO.FileNotFoundExceptionMessage    : Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.FileName   : System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089TargetSite : Void .ctor(System.Func`1[Microsoft.Azure.Commands.Common.Authentication.IServicePrincipalKeyStore])StackTrace :at Microsoft.Azure.Commands.Common.Authentication.AdalTokenProvider..ctor(Func`1 getKeyStore)at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory..ctor()at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.CreateInstance(IDataStore dataStore)at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.<>c.<InitializeAzureSession>b__2_0()at Microsoft.Azure.Commands.Common.Authentication.AzureSession.Initialize(Func`1 instanceCreator, Boolean overwrite)at Microsoft.Azure.Commands.Common.Authentication.AzureSession.Initialize(Func`1 instanceCreator)at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.InitializeAzureSession()at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.OnImport()at System.Management.Automation.Runspaces.PSSnapInHelpers.ExecuteModuleInitializer(Assembly assembly, IEnumerable`1 assemblyTypes)at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzeModuleAssemblyWithReflection(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, String helpFile, Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2& providers)at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzePSSnapInAssembly(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2& providers, String& helpFile)at System.Management.Automation.Runspaces.InitialSessionState.ImportCmdletsFromAssembly(Assembly assembly, PSModuleInfo module)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(PSModuleInfo parentModule, Boolean trySnapInName, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found, String shortModuleName, Boolean disableFormatUpdates)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(Boolean trySnapInName, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(String fileName, String moduleBase, String prefix, SessionState ss, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found)at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name)at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName_WithTelemetry(ImportModuleOptions importModuleOptions, String name)at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()at System.Management.Automation.Cmdlet.DoProcessRecord()at System.Management.Automation.CommandProcessor.ProcessRecord()Source     : Microsoft.Azure.Commands.Common.AuthenticationHResult    : -2147024894CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundExceptionFullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommandInvocationInfo        :MyCommand        : Import-ModuleScriptLineNumber : 17OffsetInLine     : 1HistoryId        : 1ScriptName       : C:\home\site\wwwroot\lcsCollector\run.ps1Line             : Import-Module d365fo.toolsPositionMessage  : At C:\home\site\wwwroot\lcsCollector\run.ps1:17 char:1+ Import-Module d365fo.tools+ ~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot     : C:\home\site\wwwroot\lcsCollectorPSCommandPath    : C:\home\site\wwwroot\lcsCollector\run.ps1InvocationName   : Import-ModuleCommandOrigin    : InternalScriptStackTrace      : at <ScriptBlock>, C:\home\data\ManagedDependencies\2206030853572750408.r\AzureRM.Profile\5.8.4\AzureRM.Profile.psm1: line 81at <ScriptBlock>, C:\home\data\ManagedDependencies\2206030853572750408.r\Azure.Storage\4.6.1\Azure.Storage.psm1: line 50at <ScriptBlock>, C:\home\site\wwwroot\lcsCollector\run.ps1: line 17PipelineIterationInfo :Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException : Result: ERROR: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.Exception             :Type       : System.IO.FileNotFoundExceptionMessage    : Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.FileName   : System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089TargetSite : Void .ctor(System.Func`1[Microsoft.Azure.Commands.Common.Authentication.IServicePrincipalKeyStore])StackTrace :at Microsoft.Azure.Commands.Common.Authentication.AdalTokenProvider..ctor(Func`1 getKeyStore)at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory..ctor()at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.CreateInstance(IDataStore dataStore)at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.<>c.<InitializeAzureSession>b__2_0()at Microsoft.Azure.Commands.Common.Authentication.AzureSession.Initialize(Func`1 instanceCreator, Boolean overwrite)at Microsoft.Azure.Commands.Common.Authentication.AzureSession.Initialize(Func`1 instanceCreator)at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.InitializeAzureSession()at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.OnImport()at System.Management.Automation.Runspaces.PSSnapInHelpers.ExecuteModuleInitializer(Assembly assembly, IEnumerable`1 assemblyTypes)at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzeModuleAssemblyWithReflection(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, String helpFile, Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2& providers)at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzePSSnapInAssembly(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2& providers, String& helpFile)at System.Management.Automation.Runspaces.InitialSessionState.ImportCmdletsFromAssembly(Assembly assembly, PSModuleInfo module)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(PSModuleInfo parentModule, Boolean trySnapInName, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found, String shortModuleName, Boolean disableFormatUpdates)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(Boolean trySnapInName, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(String fileName, String moduleBase, String prefix, SessionState ss, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found)at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name)at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName_WithTelemetry(ImportModuleOptions importModuleOptions, String name)at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()at System.Management.Automation.Cmdlet.DoProcessRecord()at System.Management.Automation.CommandProcessor.ProcessRecord()Source     : Microsoft.Azure.Commands.Common.AuthenticationHResult    : -2147024894CategoryInfo          : NotSpecified: (:) [Import-Module], FileNotFoundExceptionFullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommandInvocationInfo        :MyCommand        : Import-ModuleScriptLineNumber : 17OffsetInLine     : 1HistoryId        : 1ScriptName       : C:\home\site\wwwroot\lcsCollector\run.ps1Line             : Import-Module d365fo.toolsPositionMessage  : At C:\home\site\wwwroot\lcsCollector\run.ps1:17 char:1+ Import-Module d365fo.tools+ ~~~~~~~~~~~~~~~~~~~~~~~~~~PSScriptRoot     : C:\home\site\wwwroot\lcsCollectorPSCommandPath    : C:\home\site\wwwroot\lcsCollector\run.ps1InvocationName   : Import-ModuleCommandOrigin    : InternalScriptStackTrace      : at <ScriptBlock>, C:\home\data\ManagedDependencies\2206030853572750408.r\AzureRM.Profile\5.8.4\AzureRM.Profile.psm1: line 81at <ScriptBlock>, C:\home\data\ManagedDependencies\2206030853572750408.r\Azure.Storage\4.6.1\Azure.Storage.psm1: line 50at <ScriptBlock>, C:\home\site\wwwroot\lcsCollector\run.ps1: line 17PipelineIterationInfo :Exception: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.Stack:    at Microsoft.Azure.Commands.Common.Authentication.AdalTokenProvider..ctor(Func`1 getKeyStore)at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory..ctor()at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.CreateInstance(IDataStore dataStore)at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.<>c.<InitializeAzureSession>b__2_0()at Microsoft.Azure.Commands.Common.Authentication.AzureSession.Initialize(Func`1 instanceCreator, Boolean overwrite)at Microsoft.Azure.Commands.Common.Authentication.AzureSession.Initialize(Func`1 instanceCreator)at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.InitializeAzureSession()at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.OnImport()at System.Management.Automation.Runspaces.PSSnapInHelpers.ExecuteModuleInitializer(Assembly assembly, IEnumerable`1 assemblyTypes)at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzeModuleAssemblyWithReflection(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, String helpFile, Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2& providers)at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzePSSnapInAssembly(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2& providers, String& helpFile)at System.Management.Automation.Runspaces.InitialSessionState.ImportCmdletsFromAssembly(Assembly assembly, PSModuleInfo module)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(PSModuleInfo parentModule, Boolean trySnapInName, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found, String shortModuleName, Boolean disableFormatUpdates)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(Boolean trySnapInName, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(String fileName, String moduleBase, String prefix, SessionState ss, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags, Boolean& found)at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name)at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName_WithTelemetry(ImportModuleOptions importModuleOptions, String name)at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()at System.Management.Automation.Cmdlet.DoProcessRecord()at System.Management.Automation.CommandProcessor.ProcessRecord()
Splaxi commented 2 years ago

Hi,

The error would indicate that you can't expect it to work.

Could you explain the scenario that you want to support, by having the module to run inside an Azure Function?

FH-Inway commented 2 years ago

See also #618 for some alternatives to Azure Functions.

FH-Inway commented 1 year ago

I came across a similar error message today (see #734 ), which I think is caused by the PowerShell version. According to https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell?tabs=portal#powershell-versions, Azure Functions run with PowerShell 7.2. The d365fo.tools still require PowerShell 5.1.

So I think at least for the moment, d365fo.tools can't be used in Azure Functions.