Azure自动化Powershell Runbook静默无法加载组件 [英] Azure Automation Powershell runbook silently fails to LoadAssembly

查看:67
本文介绍了Azure自动化Powershell Runbook静默无法加载组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Powershell Runbook的新手,所以如果我缺少明显的内容,请原谅我.我正在尝试从脚本中记录Application Insights请求,但什至无法加载DLL,尽管我已经看到其他执行类似操作的代码.请注意,这是Powershell Runbook,而不是Powershell Workflow Runbook.

I'm new to Powershell Runbook, so forgive me if I'm missing something obvious. I'm trying to log an Application Insights request from my script, but can't even get the DLL to load, though I've seen other code out there that does something very similar. NOTE that this is a Powershell Runbook, not a Powershell Workflow Runbook.

这是我的代码:

Write-Output "Starting"
$assemblyPath = "C:\Modules\Global\Azure\Compute\Microsoft.ApplicationInsights.dll"
dir $assemblyPath

Write-Output "1"        
[System.Reflection.Assembly]::LoadFrom($assemblyPath)
Write-Output "2"

这是在测试"窗格中运行它时得到的输出:

And here's the output I get when running it in the Test pane:

Starting

    Directory: C:\Modules\Global\Azure\Compute
Mode                LastWriteTime         Length Name                                                                   
----                -------------         ------ ----                                                                   
------        1/11/2016   1:59 PM         152824 Microsoft.ApplicationInsights.dll                                      
1
Starting

    Directory: C:\Modules\Global\Azure\Compute
Mode                LastWriteTime         Length Name                                                                   
----                -------------         ------ ----                                                                   
------        1/11/2016   1:59 PM         152824 Microsoft.ApplicationInsights.dll                                      
1
Starting

    Directory: C:\Modules\Global\Azure\Compute
Mode                LastWriteTime         Length Name                                                                   
----                -------------         ------ ----                                                                   
------        1/11/2016   1:59 PM         152824 Microsoft.ApplicationInsights.dll                                      
1

它似乎到达了LoadAssembly,然后爬出,在放弃之前运行了3次脚本.有什么想法我做错了吗?该DLL显然存在于该位置,并且我没有得到任何错误输出来帮助我进行调试.谢谢!

It seems to get as far as the LoadAssembly and then craps out, running the script three times before giving up. Any ideas what I'm doing wrong? The DLL clearly exists at that location, and I'm not getting any error output to help me debug. Thanks!

推荐答案

看来,您对 LoadFrom 的调用正在生成大量输出.如果以交互方式运行代码并像这样更改代码,则可以看到此代码: [System.Reflection.Assembly] :: LoadFrom($ assemblyPath)|Out-String -Width 500000000 ,它将实际上生成一个 OutOfMemoryException .另外,如果您这样修改运行手册: [System.Reflection.Assembly] :: LoadFrom($ assemblyPath)|无空,您的作业将运行.现在,大量的输出使运行时崩溃.(这可能是Runbook执行引擎中的错误.)

It looks like your call to LoadFrom is generating a massive amount of output. You can see this if you run your code interactively and just change it like this: [System.Reflection.Assembly]::LoadFrom($assemblyPath) | Out-String -Width 500000000, it will actually generate an OutOfMemoryException. Alternatively, if you modify your runbook like this: [System.Reflection.Assembly]::LoadFrom($assemblyPath) | Out-Null, your job will run. Right now, this large amount of output is crashing the runtime. (This is probably a bug in the runbook execution engine.)

但是,请不要这样做! LoadFrom LoadPartial 等...在PowerShell 3中已弃用.

However, don't do that! LoadFrom, LoadPartial, etc... these are deprecated in PowerShell 3.

好处是,有一种不赞成使用的 PowerShelly 方法来执行您想要的操作.只需使用 Add-Type -Path $ assemblyPath 而不是 [System.Reflection.Assembly] :: LoadFrom($ assemblyPath).

The good thing is there is a non-deprecated PowerShelly way to do what you want. Just use Add-Type -Path $assemblyPath instead of [System.Reflection.Assembly]::LoadFrom($assemblyPath).

作为一个FYI,每当您看到作业被暂停并显示消息作业操作'Activate'不能运行,因为该过程意外停止.该作业尝试了3次."-这意味着您已经完全破坏了运行时和整个工作环境.:)我们尝试3次,以防万一我们在加载脚本或构建环境时出错,但是3次之后,我们认为这是一个错误的脚本.

As an FYI, whenever you see your job suspended and the message, "The job action 'Activate' cannot be run, because the process stopped unexpectedly. The job action was attempted 3 times." - this means you have totally crashed the runtime and your entire job environment. :) We try 3 times just in case it is something we did wrong loading your script or building the environment, but after 3 times we figure it is a bad script.

这篇关于Azure自动化Powershell Runbook静默无法加载组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆