简体   繁体   English

从Windows Task Scheduler运行控制台应用程序时遇到CryptographicException

[英]Encountering a CryptographicException when console app is run from Windows Task Scheduler

I'm deploying a console app which gathers data on a user base and sends emails to our support team. 我正在部署一个控制台应用程序,该应用程序可以在用户群上收集数据并将电子邮件发送给我们的支持团队。 There is a spreadsheet to read for which Google Spreadsheet Service is employed, therefore the corresponding class opens with the following lines: 有一个要使用Google Spreadsheet Service的电子表格,因此将打开相应的类,并带有以下几行:

const string serviceAccountEmail = "someemailaddresss";

var cert = new X509Certificate2(@"key.p12", "abigsecret", X509KeyStorageFlags.Exportable);

        var credential = new ServiceAccountCredential(
            new ServiceAccountCredential.Initializer(serviceAccountEmail) {
                Scopes = new[] { "https://spreadsheets.google.com/feeds" }
            }.FromCertificate(cert));

I did not have any problems running it locally, nor were there issues when manually launching the executable on the AWS deployment machine. 我在本地运行它没有任何问题,在AWS部署计算机上手动启动可执行文件时也没有问题。 Now this task is to be automated and therefore was set up using Windows Task Scheduler, where it fails with the stack trace below. 现在,此任务将被自动化,因此是使用Windows Task Scheduler设置的,该任务失败并显示以下堆栈跟踪。

Description: The process was terminated due to an unhandled exception.
Exception Info: System.Security.Cryptography.CryptographicException
   at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32)
   at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(System.String)
   at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(System.String, System.Object, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags)
   at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(System.String, System.String, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags)
   at (hidden).GoogleSpreadsheetReader.ReadBrokerList(System.String)
   at (hidden).Console.ReportEntryPoint..ctor()
   at (hidden).Console.ReportEntryPoint.Main(System.String[])

I have found answers which pertain to similar errors within web applications where the answer is to properly load the user profile for the app pool within IIS to enable the crypto subsystem. 我发现了与Web应用程序中类似错误有关的答案,其中答案是正确加载IIS中应用程序池的用户配置文件以启用加密子系统。 This however is a console app. 但是,这是一个控制台应用程序。 Would could be the solution? 会是解决方案吗?

And here was the actual solution: While configuring the task in Task Scheduler, indicating the exe directory under "start in" in the Actions tab fixed the issue. 这是实际的解决方案:在“任务计划程序”中配置任务时,指示“操作”选项卡中“开始于”下的exe目录解决了该问题。 Even though "start in" is marked as an optional field and the path to the executable was obviously initially provided. 即使将“开始于”标记为可选字段,并且显然最初提供了可执行文件的路径。

暂无
暂无

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

相关问题 从任务计划程序运行时,Windows服务器上的计划的C#控制台应用程序不显示控制台 - Scheduled c# console app on windows server does not show console when ran from task scheduler 从任务计划程序调试Windows控制台应用程序 - Debugging a Windows Console Application from Task Scheduler 从通过Windows Task Scheduler运行的控制台应用程序启动命令外壳 - Launch a command shell from a console application run via Windows Task Scheduler 如何从服务器上的Windows Task Scheduler运行ac#控制台应用程序 - How to run a c# console application from windows task scheduler on server 使用Windows Task Scheduler运行时无法访问sql server db的C#应用 - C# app that does not access sql server db when run with windows task scheduler 任务计划程序启动时隐藏C#控制台应用程序窗口 - Hide C# Console App Window When Started by Task Scheduler 设置为“启动时”时,控制台应用程序无法通过任务计划程序启动 - Console app not launching via task scheduler when set to "At StartUp" 现在可以在从 Windows 任务调度程序运行 .net 核心控制台应用程序时读取 appsettings.json 文件中存在的连接字符串 - Now able to read the Connection String present in appsettings.json file when running the .net core Console application from windows task scheduler 在.net应用程序中从Windows Task Scheduler捕获任务 - Catch tasks from windows task scheduler in a .net app 从Windows XAML应用运行控制台应用 - Run console app from Windows XAML app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM