c# exe throwing error only when run through task scheduler - c#-2.0

I have an exe that developed on visual studio.
When we run it on the server, it will execute with out any issues.
But when I tried to execute it through Task scheduler, it is not running.
Please find the below error message from event viewer.
Please help me to resolve the issue
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.DirectoryNotFoundException
Stack:
at System.IO.__Error.WinIOError(Int32, System.String)
at System.IO.Directory.InternalCreateDirectory(System.String, System.String, System.Object, Boolean)
at System.IO.DirectoryInfo.Create()
at CentralMarketTransfer.HEB.CentralMarketTransfer.util.SimpleLogging.LogMessageToFile(System.String)
at CentralMarketTransfer.HEB.CenteralMarketTransfer.main.ProjectMain.Main(System.String[])

Try to explicitly set the start directory for the task. You can set in Task Scheduler.
Select Task -> Right Click -> Properties -> Actions Tab -> Select Action -> Edit -> Start in (optional)

To me it seems that the current running directory is different when the exe is executed directly and when running through the task scheduler.
For reference:
What is the default working directory for a scheduled task in Windows 2008 R2?
Specifying the running directory for Scheduled Tasks using schtasks.exe

Related

Azure Pipelines | App Center test | error when including category

I'm running a job (series of tasks including nuget restore, build & signing application) on Azure DevOps to build android application and Test (Xamarin.UITest) application through Appcenter.
Test runs fine, if I don't specify any arguments on "Additional options for run" on "Test with Visual Studio App Center" task. When I do that (--include-category LandingPage) task throws error saying:
Error: Command 'test run manifest --manifest-path d:\a\12\a\AppCenterTest\manifest.json --app-path d:/a/12/b/Release/PUBLISH_PACKAGE_NAME_PHONE_ANDROID.PUBLISH_PACKAGE_NAME_PHONE_ANDROID.apk --app SampleApp/Android --devices 12345abcd --test-series DevOps --locale en_US --include-category LandingPage --quiet --token ***' failed with exception "Unknown argument --include-category"
What I'm missing?
[command works perfectly when I run appcenter test run from my local machine.]
Any help is appreciated.
For people facing this issue, make sure you're providing your --include-category AppCenterTest under Prepare Tests area not under Run tests. Additional Options under Run Tests have different purpose it seems.
failed with exception "Unknown argument --include-category
In fact, the error message has been clear to express the caused reason. For this App Center Test task in Azure Devops, this command argument --include-category does not supportted.
Please Refer to the open source of about this task: azure-pipelines-tasks/Tasks/AppCenterTestV1. You can check its logic and which arguments are supported by this task.
After you open the source file in github, go function getTestRunner and you will see that for test runner, the arguments it defined and supported to compile in this task does not include --include-category. That's why you receive the Unknown argument error.

Waiting for an available agent / Waiting for an agent to be requested

(26.07.2016)I am using TFS2015 Update3 in a VM.
When I try to queue a build through the web interface or from Team Explorer, I get the following.
Then I restart all services related to TFS in services.msc and then after some time it starts working again.
So this happens too often.
I have a custom pool running:
Is there a way to debug this behaviour?
Examining the Log files
Link to Worker log file
Link to Agent log file
Exception occurs in this order here:
Checking if artifacts directory exists C:\workspaces\agent\_work\2\a
Deleting artifacts directory
System.ComponentModel.Win32Exception (0x80004005): The directory is not empty
at Microsoft.TeamFoundation.Common.FileSpec.DeleteDirectoryLongPath(String path, Boolean recursive, Boolean followJunctionPoints)
The weird thing is, queueing new build works most of the time, this happens only sporadically
It could be, that I have opened a file from that folder in notepad with many tabs open. Will observe if this issue persists and report.
If this is happening sporadically, it might a long path exists here in artifacts:
C:\workspaces\agent_work\2\a
Or, there was a cancelled build which left the artifact directory half cleaned which exposed a bug in cleaning.
The 2.x agent isn't subject to long paths (net core) but only works with 2017+:
https://github.com/Microsoft/vsts-agent
We can troubleshoot but it would be good to get to 2017+ (2018 QU3 is out) with a 2.x agent.
If that's not an option, message me and we can dig into what I think is a cancel / state bug.

unable to publish mvc6 app due to invokepowershell failure in vs2015

I am having some serious grief trying to publish my mvc6 application due to a powershell file blockage. I ran powershell as an administrator and adjusted the execution policy. But it doesnt seem to have any impact on the publishing process in vs2015. Further to that i even tried in vain to run the Unblock-File cmdlet in the NPM.
Anyone have any ideas about how I can get this to work? the full error is below:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(386,5): Error MSB4018: The "InvokePowerShell" task failed unexpectedly.
System.Management.Automation.PSSecurityException: AuthorizationManager check failed. ---> System.Management.Automation.Host.HostException: A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message: Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning message. Do you want to run G:\_PIPELINE_MANAGEMENT\_SOURCE\_MANAGEMENT\_2016\ProjMgr\src\ProjMgr\Properties\PublishProfiles\ProjMgr-publish.ps1?
at System.Management.Automation.Internal.Host.InternalHostUserInterface.ThrowPromptNotInteractive(String promptMessage)
at System.Management.Automation.Internal.Host.InternalHostUserInterface.PromptForChoice(String caption, String message, Collection`1 choices, Int32 defaultChoice)
at Microsoft.PowerShell.PSAuthorizationManager.RemoteFilePrompt(String path, PSHost host)
at Microsoft.PowerShell.PSAuthorizationManager.CheckPolicy(ExternalScriptInfo script, PSHost host, Exception& reason)
at Microsoft.PowerShell.PSAuthorizationManager.ShouldRun(CommandInfo commandInfo, CommandOrigin origin, PSHost host, Exception& reason)
at System.Management.Automation.AuthorizationManager.ShouldRunInternal(CommandInfo commandInfo, CommandOrigin origin, PSHost host)
--- End of inner exception stack trace ---
at System.Management.Automation.Runspaces.AsyncResult.EndInvoke()
at System.Management.Automation.PowerShell.EndInvoke(IAsyncResult asyncResult)
at Microsoft.Web.Publishing.Tasks.InvokePowerShell.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
Done executing task "InvokePowerShell" -- FAILED.
Done building target "PowerShellPublish" in project "ProjMgr.xproj" -- FAILED.
Done building project "ProjMgr.xproj" -- FAILED.
Done executing task "MSBuild" -- FAILED.
Done building target "FileSystemPublish" in project "ProjMgr.xproj" -- FAILED.
Done building project "ProjMgr.xproj" -- FAILED.
2>Publish failed due to build errors. Check the error list for more details.
Create another publish profile and try again.
For me this works.
I managed to get it to publish by copying my entire project folder to the root of my local. Must be a folder permissions issue somewhere...

Grails from command line gets number format exceptions in threads and cannot recover

When running Grails in the Windows Command Prompt in development mode, after invoking run-app, I often get a few NumberFormatExceptions thrown for Threads after making changes to code and saving. This particularly happens when changing conf files or if there is a compile error in my code.
The only way to recover that I've found is to close the command prompt window, open a new one, start Grails again, then issue a stop-app and run-app.
Is there another way?
Text from the command window is below:
| Compiling 1 source files.
grails>
Exception: java.lang.NumberFormatException thrown from the UncaughtExceptionHandler in thread "Thread-14"
Exception: java.lang.NumberFormatException thrown from the UncaughtExceptionHandler in thread "Thread-24"
#BurtBeckwith found the solution to this. It appears to be related to running grails on a Windows development environment. Raised in JIRA: http://jira.grails.org/browse/GRAILS-9356. The issue occurs when you start a DOS command window, type "grails" then within grails, do run-app. The solution is to start the DOS command window and type "grails run-app" together. It runs much more stable like this. Then, closing the command window kills the java.exe task and no need to do a stop-app.

TFS Lab management Deployment Scripts

I'm trying to setup Standard Lab Environment with TFS 2012 utilizing Build-Deploy-Test workflow. I setup test controller and test agents but when the LabManagement workflow starts executing I get an exception on RunDeploymentTask activity
Initial Property Values
BuildLocation = \\S0503TFS2T\TFSPlayground\ConsoleApplicationBuild\ConsoleApplicationBuild_20121210.23
DeploymentScriptDetails = agent1 | "$(BuildLocation)\Deploy.bat" $(BuildLocation) | c:\Env
LabEnvironmentUri = vstfs:///LabManagement/LabEnvironment/4
MaxWaitTime = 00:30:00
ThrowOnError = True
UseRoleForDeployment = True
Deployment Task Logs for Machine: win7testagent1
Access is denied
Exception Message: Team Foundation Server could not complete the deployment task for machine 'win7testagent1', script '"\\S0503TFS2T\TFSPlayground\ConsoleApplicationBuild\ConsoleApplicationBuild_20121210.23\Deploy.bat"', arguments '\\S0503TFS2T\TFSPlayground\ConsoleApplicationBuild\ConsoleApplicationBuild_20121210.23' and working directory 'c:\Env'. (type LabDeploymentProcessException)
Exception Stack Trace:
Server stack trace:
at Microsoft.TeamFoundation.Lab.Workflow.Activities.RunDeploymentTask.ExecuteDeploymentTask.RunCommand(AsyncState state)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)
at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)
at System.Action`1.EndInvoke(IAsyncResult result)
at Microsoft.TeamFoundation.Lab.Workflow.Activities.RunDeploymentTask.ExecuteDeploymentTask.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
Apparently, this is security issue, that i cannot get over it
Here's how this process is explained by MSDN:
The build-deploy-test workflow starts a build, and then gets the deployment scripts.
The build definition copies the build files to the drop location.
The workflow runs each deployment script in the working directory of the specific machine or machine role that the script is assigned to.
Each deployment script retrieves build files from the drop location.
Each deployment script copies or installs the specified build files onto machines in the lab environment.
At this point the problem shows up - the workflow runs each deployment script in the working directory of the specific machine.
Both machines are in the same domain the user that runs the Build service is also in the administrators group in the remote machine. I have even shared the remote folder where the workflow is supposed to copy the files/script with everyone in the network but no luck again.
I'm doing something stupid that driving me crazy - any help or thoughts are greatly appreciated!
Best,
Rado
The following solution may fix your problem.
Steps: Create local account on the following server: local lab service account - tfslab
tfs test controller server: create local tfslab account. Also configure the tfslab as lab service account in test controller configure console
tfs test agent server: create local tfslab account and add tfslab to local admin group. Also update Visual Studio Test Agent service and Visual Studio Lab Agent Service to run as tfslab.
tfs drop folder server: create local tfslab account. And add share read permission to tfs drop folder.
Details discussion see here.
You may try to check %ErrorLevel% at the last of your bat script. I met the same error, and it turned out that that error was caused by exit code of robocopy, which returns 1 when the copy successes. I set the error code to 0, the issue was fixed.

Resources