exe.config file getting deleted when console app is run and fails - c#

I have a console application that seems to have deleted its exe.config file when it failed. The failure was logged as
2018-03-01 00:16:49.4742 - ERROR: System.IO.IOException: The device is not ready.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
at System.IO.DirectoryInfo.InternalGetFiles(String searchPattern, SearchOption searchOption)
at System.IO.DirectoryInfo.GetFiles(String searchPattern)
at [my code]...
The console app is being run by a scheduler and rerun about 8 minutes later, whereupon it failed with no output. Subsequent investigation revealed that the exe.config was missing. Restoring the missing file then allowed the app to run as expected. The initial run was done in the middle of the night and the rerun was manually triggered in the scheduling app so there's little chance of someone manually deleting the file. Also had this happen in test environments.
I've not been able to find any instances of exe.config files being deleted in stackoverflow or elsewhere so hopefully someone can help me out on this esoteric issue.
EDIT: For info, scheduling system is Cisco Tidal
EDIT 2: It appears that the deletion of the config file is linked to nlog rolling over its log file monthly - this is a pattern in the failures in other environments and now locally this morning

I have found the issue. It is with NLog indeed. When the file rolls over, it is meant to delete all but the last 12 rolled over files in our configuration. There is a bug however in that it tries to delete a lot than that - including the application exe itself. Luckily this fails as it is in use. I'll raise a bug with the nlog community on github
UPDATE: bug raised: https://github.com/NLog/NLog/issues/2607. Community has advised that the config is unsupported and a fix would be to reject it rather than exposing this unexpected behaviour. Will hopefully be fixed to avoid this issue for anyone else

Related

Unreal Engine build crashes at C# trying to open Recycle Bin file

This boggles my mind, to the point that I wonder if isn't an SDK problem.
I share an Unreal Engine (4.26) game with a (non-technical) colleague through Git. Today he received his first code files from me, and to compile it, I had him install the SDKs(windows, .Net, C++ gaming, Visual Studio) and call Generate Visual Studio Project Files. It all generated just fine.
EDIT:
Emptying the recycle bin somehow fixed it, but now the problem repeats itself:
ERROR: Unhandled exception: System.UnauthorizedAccessException: Access to the path 'D:\System Volume Information' is denied.
So this entirely seems like a permission level problem to me, but I asked him to enable developer mode, to uncheck every read-only on Epic Games and Unreal Engine, and to run it in administrator mode. Nothing works. I don't see how we can get any more permissions than this.
Former message:
ERROR: Unhandled exception: System.UnauthorizedAccessException: Access to the path 'D:$RECYCLE.BIN\S-1-5-18' is denied.
Full logfile(minus some cleanup on my part):
Log file open, 04/17/21 12:00:08
LogInit: LLM is enabled
LogInit: LLM CsvWriter: off TraceWriter: off
LogInit: Display: Running engine for game: Naptin
LogPlatformFile: Not using cached read wrapper
LogTaskGraph: Started task graph with 5 named threads and 35 total threads with 3 sets of task threads.
LogStats: Stats thread started at 5.907298
LogD3D11RHI: Loaded GFSDK_Aftermath_Lib.x64.dll
LogICUInternationalization: ICU TimeZone Detection - Raw Offset: -5:00, Platform Override: ''
LogPluginManager: Mounting plugin MeshPainting
.....lots of LogPluginManager......
LogPluginManager: Mounting plugin SteamVR
LogXGEController: Cleaning working directory: C:/Users/adpar/AppData/Local/Temp/UnrealXGEWorkingDir/
LogXGEController: Cannot use XGE Controller as Incredibuild is not installed on this machine.
LogInit: Warning: Incompatible or missing module: Naptin
Running D:/.........UNREALENGINEFOLDER/UE_4.26/Engine/Binaries/DotNET/UnrealBuildTool.exe Development Win64 -Project="D:/....UNREAL/Naptin/Naptin/Naptin.uproject" -TargetType=Editor -Progress -NoEngineChanges -NoHotReloadFromIDE
Using 'git status' to determine working set for adaptive non-unity build (D:\....UNREAL\Naptin\Naptin).
Creating makefile for NaptinEditor(no existing makefile)
#progress push 5%
Parsing headers for NaptinEditor
Running UnrealHeaderTool "D:\....UNREAL\Naptin\Naptin\Naptin.uproject" "D:\....UNREAL\Naptin\Naptin\Intermediate\Build\Win64\NaptinEditor\Development\NaptinEditor.uhtmanifest" -LogCmds="loginit warning, logexit warning, logdatabase error" -Unattended -WarningsAsErrors -abslog="C:\Users\adpar\AppData\Local\UnrealBuildTool\Log_UHT.txt" -installed
Reflection code generated for NaptinEditor in 23.9260389 seconds
#progress pop
ERROR: Unhandled exception: System.UnauthorizedAccessException: Access to the path 'D:\$RECYCLE.BIN\S-1-5-18' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
at System.IO.DirectoryInfo.EnumerateFiles()
at Tools.DotNETCommon.FileFilter.FindMatchesFromDirectory(DirectoryInfo CurrentDirectory, String NamePrefix, Boolean bIgnoreSymlinks, List`1 MatchingFileNames) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\DotNETCommon\DotNETUtilities\FileFilter.cs:line 487
at Tools.DotNETCommon.FileFilter.FindMatchesFromDirectory(DirectoryInfo CurrentDirectory, String NamePrefix, Boolean bIgnoreSymlinks, List`1 MatchingFileNames) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\DotNETCommon\DotNETUtilities\FileFilter.cs:line 495
at Tools.DotNETCommon.FileFilter.FindMatchesFromDirectory(DirectoryInfo CurrentDirectory, String NamePrefix, Boolean bIgnoreSymlinks, List`1 MatchingFileNames) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\DotNETCommon\DotNETUtilities\FileFilter.cs:line 495
at Tools.DotNETCommon.FileFilter.ApplyToDirectory(DirectoryReference DirectoryName, Boolean bIgnoreSymlinks) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\DotNETCommon\DotNETUtilities\FileFilter.cs:line 408
at Tools.DotNETCommon.FilePattern.CreateMapping(HashSet`1 Files, FilePattern& SourcePattern, FilePattern& TargetPattern) in D:\Build\++UE4\Sync\Engine\Saved\CsTools\Engine\Source\Programs\DotNETCommon\DotNETUtilities\FilePattern.cs:line 340
at UnrealBuildTool.UEBuildBinary.PrepareRuntimeDependencies(List`1 RuntimeDependencies, Dictionary`2 TargetFileToSourceFile, DirectoryReference ExeDir) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildBinary.cs:line 294
at UnrealBuildTool.UEBuildTarget.Build(BuildConfiguration BuildConfiguration, ISourceFileWorkingSet WorkingSet, Boolean bIsAssemblingBuild, List`1 SpecificFilesToCompile) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildTarget.cs:line 1786
at UnrealBuildTool.BuildMode.CreateMakefile(BuildConfiguration BuildConfiguration, TargetDescriptor TargetDescriptor, ISourceFileWorkingSet WorkingSet) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Modes\BuildMode.cs:line 615
at UnrealBuildTool.BuildMode.Build(List`1 TargetDescriptors, BuildConfiguration BuildConfiguration, ISourceFileWorkingSet WorkingSet, BuildOptions Options, FileReference WriteOutdatedActionsFile, Boolean bSkipPreBuildTargets) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Modes\BuildMode.cs:line 257
at UnrealBuildTool.BuildMode.Execute(CommandLineArguments Arguments) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\Modes\BuildMode.cs:line 226
at UnrealBuildTool.UnrealBuildTool.Main(String[] ArgumentsArray) in D:\Build\++UE4\Sync\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 550
LogInit: Warning: Still incompatible or missing module: Naptin
LogCore: Engine exit requested (reason: EngineExit() was called)
LogExit: Preparing to exit.
LogExit: Exiting.
Log file closed, 04/17/21 12:02:43
We have tried a few things, like generating again, or copypasting all of our assets to a new project: if we copy the assets, all good, if we copy the code, the same crash.
This happens only on his machine, so I'm kind of at a loss for words. He did not delete any files, the only difference between his machine and mine is that his SDK is more up-to-date by a few weeks.
I'd really appreciate any clue regarding why this file comes up in the build or how to stop it from crashing. The C++ code doesn't seem to be the issue at all, and he can't start Unreal Engine anymore.

Wix CustomAction can't access written files with before InstallFinalize

I have a Wix project which should install my c# Application. File Copy and Firewall exceptions are already working. Now I want to modify json config files with a custom action. I want to read all json files, change some values and write them back to program files. Here is my CA definition:
<CustomAction Id="PrepareConfigurationFilesCustomAction" BinaryKey="InstallerCA" DllEntry="PrepareConfigurationFilesCustomAction" Execute="immediate" Impersonate="no" Return="check" />
<CustomAction Id="CreateConfigurationFiles" BinaryKey="InstallerCA" DllEntry="CreateConfigurationFiles" Execute="deferred" Impersonate="no" Return="check" />
<Custom Action="PrepareConfigurationFilesCustomAction" Before="CreateConfigurationFiles">NOT Installed AND NOT REMOVE</Custom>
<Custom Action="CreateConfigurationFiles" Before="InstallFinalize">NOT Installed AND NOT REMOVE</Custom>
If I open the .msi wirth Orca the order of the Actios seems to be right.
enter image description here
InstallFiles 4000
PrepareConfigurationFilesCustomAction NOT Installed AND NOT REMOVE 6598
CreateConfigurationFiles NOT Installed AND NOT REMOVE 6599
But when I run the .msi I get the exception
Excetion TrownSystem.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files\Vendor\Product\etc\Configurations'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
at System.IO.Directory.GetFiles(String path)
at Vendor.Application.Product.Setup.Actions.CustomActionData.ConfigurationFilesCustomActionData.CreateSessionCustomActionData(Session session) in C:\work\\Projects\Installation\Packages\Product.Workstation\Setup.Actions\CustomActionData\ConfigurationFilesCustomActionData.cs:line 99
When I attach the debugger I can see in the code, and in the file system, that the files are not present.
If I change the first Ca (PrepareConfigurationFilesCustomAction) to Execute="deferred", the files are written but I can't access session values...
Any Ideas or solutions for me?
Thanks!
Solution?: The best solution is to install the JSON files to a read-only location and then use your application to copy them to the user profile and update them according to what you need. This is not always possible - such as when there is no application binary to lauch.
Access Denied: You can not write to locations under program files as a normal user. Here is a piece on that issue: System.UnauthorizedAccessException while running .exe under program files
Technical: The reason for the behavior you see is that the InstallExecuteSequence is processed twice. First in "immediate mode" which runs immediate mode custom actions and builds a transaction script for execution. When you reach InstallFinalize the sequence runs again from InstallInitialize and at this point the system is updated with file installation, registry changes, etc... Custom actions in this mode are deferred. They can not directly access properties. The property values have to be "sent" to them via a mecanism called CustomActionData. Quite clunky. Not needed if you use the application to do the work?
The CustomActionData concept has been so well explained before by others, that I just link to the information you can access elsewhere:
Tip: MSI Properties and Deferred Execution
How to Access Windows Installer Property in Deferred Execution
Deferred mode
An ingenious way to use JSON to serialize / deserialize properties for deferred mode.

Android build error "failed to create JavaTypeInfo for class" :Xamarin

Following this tutorial https://github.com/Vidyo/vidyo.io-connector-xamarin I downloaded the app without making any changes.
When I build the app, I get the following error:
Severity Code Description Project File Line Suppression State
Error Failed to create JavaTypeInfo for class: Android.Support.V4.View.Accessibility.AccessibilityManagerCompat/ITouchExplorationStateChangeListenerImplementor due to MAX_PATH: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\User\Desktop\vidyo.io-connector-xamarin-master\vidyo.io-connector-xamarin-master\VidyoConnector.Android\obj\Debug\90\android\src\mono\android\support\v4\view\accessibility\AccessibilityManagerCompat_TouchExplorationStateChangeListenerImplementor.java'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalDelete(String path, Boolean checkHost)
at System.IO.File.Delete(String path)
at Xamarin.Android.Tools.Files.CopyIfStreamChanged(Stream stream, String destination)
at Xamarin.Android.Tasks.Generator.CreateJavaSources(TaskLoggingHelper log, IEnumerable`1 javaTypes, String outputPath, String applicationJavaClass, String androidSdkPlatform, Boolean useSharedRuntime, Boolean generateOnCreateOverrides, Boolean hasExportReference) VidyoConnector.Android
What is the possible fix for this?
That seems a problem with long path in windows. Put the project folder on the root, say C://yourproject. Then, clean your solution and build.
#LawrenceWlt is correct but I would like to add some more information.
Is is due to Maximum Path Length Limitation
In the Windows API (with some exceptions discussed in the following
paragraphs), the maximum length for a path is MAX_PATH, which is
defined as 260 characters.
https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
If you are on Windows 10, Version 1607 or later you can Enable Long Paths:
The registry key Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled (Type: REG_DWORD) must exist and be set to 1.
The application manifest must also include the longPathAware element.
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<ws2:longPathAware>true</ws2:longPathAware>
</windowsSettings>
</application>
https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation#enable-long-paths-in-windows-10-version-1607-and-later
I got a similar error from Experimental Mobile Blazor Bindings:
https://github.com/xamarin/MobileBlazorBindings
Failed to generate Java type for class:
Android.Support.V4.View.Accessibility.AccessibilityManagerCompat/IAccessibilityStateChangeListenerImplementor
due to MAX_PATH: System.IO.DirectoryNotFoundException: Could not find
a part of the path
'C:\Users\User\Desktop\MobileBlazorBindings-master\samples\MobileBlazorBindingsXaminals\MobileBlazorBindingsXaminals.Android\obj\Debug\90\android\src\mono\android\support\v4\view\accessibility\AccessibilityManagerCompat_AccessibilityStateChangeListenerImplementor.java'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalDelete(String path, Boolean checkHost) at
System.IO.File.Delete(String path) at
Xamarin.Android.Tools.Files.CopyIfStreamChanged(Stream stream, String
destination) at
Xamarin.Android.Tasks.GenerateJavaStubs.CreateJavaSources(IEnumerable`1
javaTypes, TypeDefinitionCache
cache) MobileBlazorBindingsXaminals.Android
Adding this to the Android projects's .csproj file fixed the issue for me:
<PropertyGroup>
<IntermediateOutputPath>C:\E</IntermediateOutputPath>
</PropertyGroup>
It writes the intermediate Android files to a folder of your choice - obviously choose a really short one to avoid long paths!
There is another solution that hasn't been mentioned yet: Create a Directory Junction and point it to your solution directory. Place the junction at the root-level, then run the solution from there.
This approach will enable you to workaround the MAX_PATH issue without having to move your project or upgrade to Windows 10.
For example, let's say you store all your code in C:\dev, all your repos in C:\dev\repos, all your Git repos in C:\dev\repos\git, all your Xamarin Git repos in C:\dev\repos\git\xamarin, and all the mobile apps you've built for your largest client in C:\dev\repos\git\xamarin\isis (hey it's not my place to judge). Your latest project can be found in C:\dev\repos\git\xamarin\isis\satellite-tracker\src, but you can't get it to build because the path is too long.
So we create a new directory, C:\J, which will hold this and any other junctions we create for this workaround on other projects. Then open a command prompt as Administrator and navigate to C:\J. Then enter the following command:
mklink /J SatTrack C:\dev\repos\git\xamarin\isis\satellite-tracker\src
Now you can access your solution file from C:\J\SatTrack. If you open it from there, Visual Studio will use that path instead of the longer one and you should be fine after a clean/rebuild.
A simple solution that works great is changing the build output folder in Android Project -> Properties -> Build -> Output path

Continuous Integration build succeeds, Manual build fails

My Team Project consists of a Web Forms application and WCF Services, in two separate solutions (the WCF services are hosted on a server within the domain, the web app is in the DMZ).
I have two build definitions for my Team Project: a CI build and a manual build
Yesterday I merged a branch back into my trunk to prepare for a deployment. When I checked in my merge the CI build kicked off...and succeeded. So then I queued the manual build (the manual build is what ends up on prod server). The manual build failed. It fails everytime I run it now, however the CI build succeeds every time. The error from the build log is pasted below. I don't know how I broke this build, and I'm confused as to why the CI build succeeds but the manual build fails (same build definition except the drop location is different and the trigger is different).
Error:
Exception Message: Access to the path 'C:\Builds\1\My Web App\My Web
App\Sources\MyAppWcfServices\Services\Messages' is denied. (type
UnauthorizedAccessException) Exception Stack Trace: at
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator1.CommonInit() at
System.IO.FileSystemEnumerableIterator1..ctor(String path, String
originalUserPath, String searchPattern, SearchOption searchOption,
SearchResultHandler`1 resultHandler, Boolean checkHost) at
System.IO.Directory.InternalGetFileDirectoryNames(String path, String
userPathOriginal, String searchPattern, Boolean includeFiles, Boolean
includeDirs, SearchOption searchOption, Boolean checkHost) at
System.IO.Directory.InternalGetDirectories(String path, String
searchPattern, SearchOption searchOption) at
Microsoft.TeamFoundation.Common.FileSpec.DeleteDirectoryInternal(String
path) at
Microsoft.TeamFoundation.Common.FileSpec.DeleteDirectoryInternal(String
path) at
Microsoft.TeamFoundation.Common.FileSpec.DeleteDirectoryInternal(String
path) at
Microsoft.TeamFoundation.Common.FileSpec.DeleteDirectoryInternal(String
path) at
Microsoft.TeamFoundation.Common.FileSpec.DeleteDirectory(String path,
Boolean recursive) at
Microsoft.TeamFoundation.Build.Workflow.Activities.DeleteDirectory.Execute(CodeActivityContext
context) at
System.Activities.CodeActivity.InternalExecute(ActivityInstance
instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at
System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor
executor, BookmarkManager bookmarkManager, Location resultLocation)
Things I've read/tried:
TFS 2012 Build "Access to Path Denied"
Tool to find duplicate copies in a build (I didn't run the tool,
couldn't find a log file named like the example...confused)
I do not have my obj or bin directories in version control.
This build definition has been working great for months, up until yesterday. I'm not sure what happened when I merged that would've caused this. There were no conflicts in my merge, it was easy peasy....until I tried to build.
just go to the Build controller server and stop the "Visual Studio Team Foundation Build Service Host 2013" and delete the Files or folder which you have the error in your message and start the service again
Have you checked if the actual file is locked? try a tool like unlocker http://www.emptyloop.com/unlocker
I have seen this error happening when a particular folder/file is opened in iexplorer/cmd.exe etc (either by you or some other user). When TFS tries to clean up the directory and get the latest file, it will fail as it is used by another process.
If you have access to the server, then open the taskmanager -> process and close all the iexplorer.exe/cmd.exe process from other users. Hopefully that will fix it.

DirectoryNotFoundException when accessing ProgramData on Vista - Could not find a part of the path - WinIOError

Occasionally some users of our software report issues that are caused by wired DirectoryNotFoundException exceptions. This happens only to some users running Vista. Not all users running Vista have this problem. There were no reports of this issue from users running Win7 or XP (however that does not prove that this issue does not happen on these systems - we just don't have such reports).
Our software stores some graphics data inside ProgramData folder. When program tries to read those files the following exception is thrown:
Message: Could not find a part of the path 'C:\ProgramData\My App Name\Subfolder\Subfolder'.
mscorlib
in System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
in System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption)
in System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption)
in System.IO.Directory.GetFiles(String path)
The path is C:\ProgramData\My App Name\Subfolder\Subfolder. Folder exists - I'm 100% sure. It was created by NSIS installer. It's writeable to all users (or at least it should be as that's how we set it with NSIS script). User confirms that the folder exists - he is able to navigate to that location using Windows Explorer.
At first I thought it was the UAC issue, but the exception says Could not find a part of the path. This drives me crazy as we are unable to reproduce the issue on our test systems. No matter the configuration. XP, Vista, Win7 - on our machines it just works.
Finally we found a user that had the same issue and was willing to help with testing. The root cause of this error seems to be the NSIS installer which creates folder with one wrong character. No one noticed that because that char looks almost identical to the one that was supposed to be created. So DirectoryNotFoundException was indeed right.
The NSIS was supposed to create a folder with ń char
// U+0144 ń c5 84 LATIN SMALL LETTER N WITH ACUTE
but instead created a folder with ñ char
// U+00F1 ñ c3 b1 LATIN SMALL LETTER N WITH TILDE
The wired part is that happens only on some machines and we could not reproduce that.
Lesson for today: never fully trust your users when it comes to debugging. Even screenshot provided by the user was misleading as it displayed only contents of the folder in question.

Categories