简体   繁体   English

创建RunSpace时发生内部错误

[英]Internal Error Occurred When Creating RunSpace

I have an app which allows user's to update other user's out of office message on Exchange via a simple web interface. 我有一个应用程序,允许用户通过简单的Web界面在Exchange上更新其他用户的不在办公室的邮件。

My initial attempt at creating this used using Microsoft.Exchange.WebServices to connect to Exchange services, but I had to abandon this (even though it did work) due to the permissions required on the system account (an account updating OOF messages via EWS requires FULL mailbox permissions). 我最初尝试使用Microsoft.Exchange.WebServices创建此连接来连接到Exchange服务,但由于系统帐户(通过EWS更新OOF邮件的帐户需要使用该帐户),因此我不得不放弃了此操作(即使它确实起作用了) 完整的邮箱权限)。

So to overcome this, I created the following class, which uses PowerShell remoting to achieve the same thing: 因此,为了克服这一点,我创建了以下类,该类使用PowerShell远程处理来实现相同的目的:

public class ExchangeShell
{
    private Runspace MyRunSpace;
    private PowerShell MyPowerShell;
    private Uri ExchangeServer;

    public ExchangeShell()
    {
        var exchangeserverurl = new Uri("http://EXCHANGESERVER/PowerShell");
        var psCredential = GetCredentials();
        var connectionInfo = new WSManConnectionInfo(exchangeserverurl, "http://schemas.microsoft.com/powershell/Microsoft.Exchange", psCredential);

        try
        {
            MyRunSpace = RunspaceFactory.CreateRunspace(connectionInfo);
        }
        catch (Exception ex)
        {
            Email.Send($"Unable to connect \n\n Error: {ex.Message} ");
            Environment.Exit(Environment.ExitCode);
        }
    }

    public OofSettings GetOofSettings(string email)
    {
        using (MyRunSpace)
        {
            MyRunSpace.Open();

            using (var powerShell = PowerShell.Create())
            {
                powerShell.Runspace = MyRunSpace;

                var command = new PSCommand();

                command.AddCommand("Get-MailboxAutoReplyConfiguration");
                command.AddParameter("Identity", email);

                powerShell.Commands = command;

                var result = powerShell.Invoke();

                var oofSetting = new OofSettings();

                oofSetting.State = (OofState)Enum.Parse(typeof(OofState), result[0].Properties["AutoReplyState"].Value.ToString());
                oofSetting.Duration = new TimeWindow((DateTime)result[0].Properties["StartTime"].Value, (DateTime)result[0].Properties["EndTime"].Value);
                oofSetting.ExternalAudience = (OofExternalAudience)Enum.Parse(typeof(OofExternalAudience), result[0].Properties["ExternalAudience"].Value.ToString());
                oofSetting.InternalReply = result[0].Properties["InternalMessage"].Value.ToString();
                oofSetting.ExternalReply = result[0].Properties["ExternalMessage"].Value.ToString();

                return oofSetting;
            }
        }
    }

    private PSCredential GetCredentials()
    {
        var secureString = new SecureString();
        foreach (char c in @"PASSWORD")
        {
            secureString.AppendChar(c);
        }
        return new PSCredential("SERVICEACCOUNT", secureString);
    }
}

This also works when run locally on my machine or as an EXE on the server. 当在我的计算机上本地运行或作为服务器上的EXE运行时,此方法也适用。

However, when I host this over IIS I am seeing an error on this line: 但是,当我通过IIS托管此主机时,我在此行看到错误:

MyRunSpace = RunspaceFactory.CreateRunspace(connectionInfo);

An internal error occurred. 发生了内部错误。

This is not a very helpful error message and I am not sure how I can go about debugging this. 这不是非常有用的错误消息,并且我不确定如何调试此消息。 Does anyone have any suggestions on this? 有人对此有任何建议吗?


Update 更新资料

I attached a tracer in web.config and here is some trace information after selecting a user to retrieve their out of office details: 我在web.config附加了一个跟踪器,这是在选择用户以检索其不在办公室的详细信息后的一些跟踪信息:

Category      Message                  From First(s)     From Last(s)
aspx.page     Begin PreInit   
aspx.page     End PreInit              0.000025          0.000025 
aspx.page     Begin Init               0.000035          0.000009 
aspx.page     End Init                 0.000057          0.000022 
aspx.page     Begin InitComplete       0.000065          0.000008 
aspx.page     End InitComplete         0.000073          0.000008 
aspx.page     Begin PreLoad            0.000081          0.000008 
aspx.page     End PreLoad              0.000093          0.000012 
aspx.page     Begin Load               0.000101          0.000008 

But I really don't know what to make of this information - it doesn't seem to reveal much about what is actually going on between the runspace and the server.. 但是我真的不知道该怎么处理这些信息-它似乎并没有太多揭示运行runspace和服务器之间实际发生的runspace

Stack Trace: 堆栈跟踪:

at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.Initialize(Uri connectionUri, WSManConnectionInfo connectionInfo) at System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager..ctor(Guid runspacePoolInstanceId, WSManConnectionInfo connectionInfo, PSRemotingCryptoHelper cryptoHelper) at System.Management.Automation.Remoting.ClientRemoteSessionDSHandlerImpl..ctor(ClientRemoteSession session, PSRemotingCryptoHelper cryptoHelper, RunspaceConnectionInfo connectionInfo, URIDirectionReported uriRedirectionHandler) at System.Management.Automation.Remoting.ClientRemoteSessionImpl..ctor(RemoteRunspacePoolInternal rsPool, URIDirectionReported uriRedirectionHandler) at System.Management.Automation.Internal.ClientRunspacePoolDataStructureHandler..ctor(RemoteRunspacePoolInternal clientRunspacePool, TypeTable typeTable) at System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal..ctor(Int32 minRunspaces, Int32 maxRunspaces, Typ 在System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.ctor(Guid runspacePoolInstanceId,WSManConnectionInfo connectionInfo,PSRemotingCryptoHelper的System.Management.Automation.Remoting.Client.WSManClientSessionTransportManager.Initialize(Uri connectionUri,WSManConnectionInfo connectionInfo)处.Automation.Remoting.ClientRemoteSessionDSHandlerImpl..ctor(ClientRemoteSession会话,PSRemotingCryptoHelper cryptoHelper,RunspaceConnectionInfo connectionInfo,URIDirectionReported uriRedirectionHandler)在System.Management.Automation.Remoting.ClientRemoteSessionImpl.ctor(RemoteRunspacePoolInternal。 .ClientRunspacePoolDataStructureHandler..ctor(RemoteRunspacePoolInternal clientRunspacePool,TypeTable typeTable)在System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal..ctor(Int32 minRunspaces,Int32 maxRunspaces,Typ eTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo) at System.Management.Automation.Runspaces.RunspacePool..ctor(Int32 minRunspaces, Int32 maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo) at System.Management.Automation.RemoteRunspace..ctor(TypeTable typeTable, RunspaceConnectionInfo connectionInfo, PSHost host, PSPrimitiveDictionary applicationArguments) at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(RunspaceConnectionInfo connectionInfo, PSHost host, TypeTable typeTable, PSPrimitiveDictionary applicationArguments) at SetOutOfOffice.ExchangeShell..ctor() eTable typeTable,PSHost主机,PSPrimitiveDictionary applicationArguments,RunspaceConnectionInfo connectionInfo),位于System.Management.Automation.Runspaces.RunspacePool..ctor(Int32 minRunspaces,Int32 maxRunspaces,TypeTable typeTable,PSHost主机,PSHost,PSPrimitiveDictionary applicationArguments,RunspaceConnectionInfo connectionInfo。 .RemoteRunspace.ctor(TypeTable typeTable,RunspaceConnectionInfo connectionInfo,PSHost主机,PSPrimitiveDictionary applicationArguments)位于System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(RunspaceConnectionInfo connectionInfo,PSHost主机,TypeTable typeTable,PSPrimitiveDictionary applicationArguments)在SetOutOftor.ExchangeShell。 ()

If you want to debug you should be able to use tracing in .NET or just attach the debugger 如果要调试,则应该可以在.NET中使用跟踪,也可以仅附加调试器

A common issue is failing certificate checks so you might want to try to bypass those eg 一个常见的问题是证书检查失败,因此您可能希望尝试绕过那些检查,例如

connectionInfo.SkipCACheck = true; connectionInfo.SkipCACheck = true; connectionInfo.SkipCNCheck = true; connectionInfo.SkipCNCheck = true; connectionInfo.MaximumConnectionRedirectionCount = 4; connectionInfo.MaximumConnectionRedirectionCount = 4;

This issue was being caused because I had the wrong version of PowerShell installed on the server. 引起此问题的原因是我在服务器上安装了错误版本的PowerShell。

It is a shame that the Internal Error message does not mention this, but probably a good one to check when this error occurs. 很遗憾, Internal Error消息没有提到这一点,但是可能是检查何时发生此错误的好人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 创建RunSpace时如何使用PowerShell 2或3? - How to PowerShell 2 or 3 when creating RunSpace? 错误消息:创建 TLS 客户端凭据时发生致命错误。 内部错误状态为 10013 - Error message: A fatal error occurred while creating a TLS client credential. The internal error state is 10013 创建路由时出错 - An error occurred while creating a route 使用X509Certificate2加载pfx文件时出现“内部错误。” - “An internal error occurred.” when loading pfx file with X509Certificate2 为nlog创建配置节处理程序时出错:在NLog.Targets.DatabaseParameterInfo上设置属性'Layout'时出错 - Error occurred creating the configuration section handler for nlog: Error when setting property 'Layout' on NLog.Targets.DatabaseParameterInfo 在Visual Studio中创建SharePoint WebPart时出错-“生成项目时发生错误” - Error when creating SharePoint WebPart in Visual Studio - “An error occurred while generating the project” PSRemotingTransportException在C#中创建远程PowerShell Runspace - PSRemotingTransportException in creating a Remote PowerShell Runspace in C# 连接到WCF RESTfull服务时,创建Ssl服务器凭据时发生致命错误。 - A Fatal Error Occurred While Creating An Ssl Server Credential when connect to WCF RESTfull service 创建配置节处理程序时发生错误 - An error occurred creating the configuration section handler “创建配置节处理程序时发生错误” - - “An error occurred creating the configuration section handler for” -
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM