FileSyncProvider Exception sourceDirectory is write protected for 'filesync.metadata' - c#

in my program i have an exception, because i want to synchronize a local directory with a write protected networkDirectory.
Message:
Microsoft.Synchronization.MetadataStorage.MetadataStorageEngineException: Fehler bei einem Speichermodulvorgang. Fehlercode: 25039 (HRESULT = 0x80004005, Quellen-IID = {0C733A7A-2A1C-11CE-ADE5-00AA0044773D}, Parameter=(0, 0, 0, H:\filesync.metadata, , , )).
---> System.Runtime.InteropServices.COMException: Fehler bei einem Speichermodulvorgang. Fehlercode: 25039 (HRESULT = 0x80004005, Quellen-IID = {0C733A7A-2A1C-11CE-ADE5-00AA0044773D}, Parameter=(0, 0, 0, (sourceNetworkDirectory)\filesync.metadata, , , )).
I would like to avoid writing the 'filesync.metadata' to the sourceDirectory, or maybe change the path for writing the metaFile
Can someone help me?
Greetings from Andre

the constructor for the file sync provider allows you to specify an alternate location for the metadata file.

Related

ConfigurationManager.OpenMappedExeConfiguration "because it is being used by another process"

I'd like to re-read the MySolution.main.config (my app.config) thanks FileSystemWatcher when users modify it. I built a wrapper called FileWatcher.
Catching OnChanged event with this piece of code
var map = new ExeConfigurationFileMap { ExeConfigFilename = _appConfigFilePath };
var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
raises this exception
System.Configuration.ConfigurationErrorsException HResult=0x80131902
Message=An error occurred loading a configuration file: The process
cannot access the file
'C:\Source\Solutions\MySolution_1.2.3\MySolution\bin\Debug\MySolution.main.config'
because it is being used by another process.
(C:\Source\Solutions\MySolution_1.2.3\MySolution\bin\Debug\MySolution.main.config)
Source=System.Configuration.ConfigurationManager StackTrace: at
System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean
ignoreLocal) in
//src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationSchemaErrors.cs:line
71 at
System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors
schemaErrors) in
//src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/BaseConfigurationRecord.cs:line
3634 at System.Configuration.Configuration..ctor(String
locationSubPath, Type typeConfigHost, Object[]
hostInitConfigurationParams) in
//src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/Configuration.cs:line
75 at
System.Configuration.ClientConfigurationHost.OpenExeConfiguration(ConfigurationFileMap
fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String
exePath) in
//src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ClientConfigurationHost.cs:line
485 at
System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap
fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String
exePath, Boolean preLoad) in
//src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationManager.cs:line
214 at
System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(ExeConfigurationFileMap
fileMap, ConfigurationUserLevel userLevel) in
//src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationManager.cs:line
192 at
Siav.MySolution.Log.ConfigurationUtil.FileWatcher.OnChanged(Object
sender, FileSystemEventArgs e) in
C:\Source\Solutions\MySolution_1.2.3\Siav.MySolution.Log\ConfigurationUtil\FileWatcher.cs:line
60 at System.IO.FileSystemWatcher.OnChanged(FileSystemEventArgs e)
in f:\dd\NDP\fx\src\services\io\system\io\FileSystemWatcher.cs:line
822 at System.IO.FileSystemWatcher.NotifyFileSystemEventArgs(Int32
action, String name) in
f:\dd\NDP\fx\src\services\io\system\io\FileSystemWatcher.cs:line 773
at System.IO.FileSystemWatcher.CompletionStatusChanged(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* overlappedPointer) in
f:\dd\NDP\fx\src\services\io\system\io\FileSystemWatcher.cs:line 594
at
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32
errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) in
f:\dd\ndp\clr\src\BCL\system\threading\overlapped.cs:line 121
This exception was originally thrown at this call stack:
System.IO.__Error.WinIOError(int, string) in __error.cs
System.IO.FileStream.Init(string, System.IO.FileMode, System.IO.FileAccess, int, bool, System.IO.FileShare, int,
System.IO.FileOptions,
Microsoft.Win32.Win32Native.SECURITY_ATTRIBUTES, string, bool, bool,
bool) in filestream.cs
System.IO.FileStream.FileStream(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare) in filestream.cs
System.Configuration.Internal.InternalConfigHost.StaticOpenStreamForRead(string)
in InternalConfigHost.cs
System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.OpenStreamForRead(string)
in InternalConfigHost.cs
System.Configuration.ClientConfigurationHost.OpenStreamForRead(string)
in ClientConfigurationHost.cs
System.Configuration.UpdateConfigHost.OpenStreamForRead(string) in UpdateConfigHost.cs
System.Configuration.ImplicitMachineConfigHost.OpenStreamForRead(string)
in ImplicitMachineConfigHost.cs
System.Configuration.BaseConfigurationRecord.InitConfigFromFile() in BaseConfigurationRecord.cs
Inner Exception 1: IOException: The process cannot access the file
'C:\Source\Solutions\MySolution_1.2.3\MySolution\bin\Debug\MySolution.main.config'
because it is being used by another process.
I tried with a simple lock, it doesn't work.
This is the constructor of my wrapper
public FileWatcher(string appConfigFilePath)
{
_appConfigFilePath = appConfigFilePath;
_lastRead = DateTime.MinValue;
var watcher = new FileSystemWatcher(Path.GetDirectoryName(_appConfigFilePath))
{
Filter = Path.GetFileName(_appConfigFilePath),
NotifyFilter = NotifyFilters.LastWrite,
EnableRaisingEvents = true
};
watcher.Changed += OnChanged;
watcher.Error += OnError;
}
Any suggestions?
Thanks
I had to manage some retry to access the file as log4net does. I suggest to you to do the same (log4net source is available on github)

Cudafy.Net System.ComponentModel.Win32Exception: The system cannot find the file specified

I downloaded cudafy here: https://github.com/lepoco/CUDAfy.NET/releases/tag/v.1.0.0.
I use VS 2022, .NET 4.8.
When executing this code, I get System.ComponentModel.Win32Exception.
CudafyModes.Target = eGPUType.Cuda;
CudafyModes.DeviceId = 0;
CudafyTranslator.Language = CudafyModes.Target == eGPUType.OpenCL ? eLanguage.OpenCL : eLanguage.Cuda;
if (CudafyHost.GetDeviceCount(CudafyModes.Target) == 0)
throw new System.ArgumentException("No suitable devices found.", "original");
GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
CudafyModule km = CudafyTranslator.Cudafy(); //THE EXCEPTION IS HERE
gpu.LoadModule(km);
StackTrace:
in System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
in Cudafy.NvccExe.getClExeDirectory()
in Cudafy.CompilerHelper.Create(ePlatform platform, eArchitecture arch, eCudafyCompileMode mode, String workingDir, Boolean debugInfo)
in Cudafy.Translator.CudafyTranslator.Cudafy()
in Game.Position..ctor() in C:\Users\Lenovo\Desktop\simple\simple\Position.cs:line 464
in Game.Position.StartPos() in C:\Users\Lenovo\Desktop\simple\simple\Position.cs:line 490
in Game.Board..ctor() in C:\Users\Lenovo\Desktop\simple\simple\Board.cs:line 189
in Game.FrmMain..ctor() in C:\Users\Lenovo\Desktop\simple\simple\FrmMain.cs:line 18
in Game.Program.Main() in C:\Users\Lenovo\Desktop\simple\simple\Program.cs:line 19
Exception information:
ErrorCode -2147467259 int
HResult -2147467259 int
HelpLink null string
InnerException null
NativeErrorCode 2 int
Source "System" string
TargetSite {Boolean StartWithCreateProcess(System.Diagnostics.ProcessStartInfo)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
The Path environment variable is declared:
Path C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\Hostx64\x64
Cuda Toolkit 11.6 has been downloaded.
What can I do about it?
I solved the problem by connecting the source code. In particular, the program did not find the path to the utility vswhere.exe. Also the CUDA Toolkit required VS2010.

KeyNotFoundException in Visual Studio Extension

I am currently writing a Visual Studio Extension, creating glyph tags. First I created a example project, there is everything running fine and it's creating the glyphs. I implemented it now to my main project and got this exception, but I don't know what is missing.
System.Collections.Generic.KeyNotFoundException: Der angegebene Schlüssel war nicht im Wörterbuch angegeben.bei System.Collections.Generic.Dictionary2.get_Item(TKey key)bei Microsoft.VisualStudio.Text.Editor.Implementation.GlyphMarginVisualManager1.AddGlyph(TGlyphTag tag, SnapshotSpan span)bei Microsoft.VisualStudio.Text.Editor.Implementation.GlyphMargin1.RefreshGlyphsOver(ITextViewLine textViewLine)bei Microsoft.VisualStudio.Text.Editor.Implementation.GlyphMargin1.OnLayoutChanged(Object sender, TextViewLayoutChangedEventArgs e)bei Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent[TArgs](Object sender, EventHandler`1 eventHandlers, TArgs args) --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)
This is my code:
if (classification.ClassificationType.Classification.ToLower().Contains("comment"))
{
//if the word "todo" is in the comment,
//create a new TodoTag TagSpan
int index = classification.Span.GetText().ToLower().IndexOf(m_searchText);
if (index != -1)
{
yield return new TagSpan<IssueTag>(new SnapshotSpan(classification.Span.Start + index, m_searchText.Length), new IssueTag());
}
}
The exception occurs at "yield return"

C# change console encoding error (bad descriptor)

Today i run Visual Studio and open my project, that i not opened about 5 months.
And running test (it was be OK) invoke IOException with additional information: "Bad descriptor".
It was in this line:
var defaultConsoleEncoding = Console.InputEncoding;
Console.InputEncoding = TryGetEncoding("UTF-8"); // <--- There is error
...
public static Encoding TryGetEncoding(string encoding)
{
try
{
return Encoding.GetEncoding(encoding);
}
catch (ArgumentException)
{
Logger.WarnAndPrint($"Can't using {encoding} encoding. Fallback to utf-8");
return Encoding.UTF8;
}
}
All my tests were OK, but now all fails with that error. I never chage code in project. And i try many encodings - nothing work.
What's the problem?
P.S. This is stack trace
System.IO.IOException was unhandled by user code
HResult=-2147024890
Message=Неверный дескриптор.
Source=mscorlib
StackTrace:
в System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
в System.Console.set_InputEncoding(Encoding value)
в PasswordListGenerator.Substitutions.Substitution.Process() в C:\GITHUB\passwordlistgenerator\PasswordListGenerator\PasswordListGenerator\Substitutions\Substitution.cs:строка 89
в PasswordListGeneratorTest.SubstitutionTests.SkipManySymbols_ShouldReturnSubstitutions() в C:\GITHUB\passwordlistgenerator\PasswordListGenerator\PasswordListGeneratorTest\SubstitutionTests.cs:строка 588
InnerException:

System.Printing.PrintServer Win32Exception Cannot create a file when that file already exists

I occasionally get an unanticipated exception thrown when I try creating a new variable in my code, and I am at a total loss trying to understand what might be causing the issue.
Any guidance or suggestions will be gratefully received
Thanks!
The code ...
using System.Printing;
var ps = new PrintServer();
The exception ...
System.ComponentModel.Win32Exception (0x80004005): Cannot create a file when that file already exists
at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D wc_d)
at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
at System.Windows.Threading.Dispatcher..ctor()
at System.Windows.Threading.Dispatcher.get_CurrentDispatcher()
at System.Printing.PrintServer.Initialize(String path, String[] propertiesFilter, PrinterDefaults printerDefaults)
at System.Printing.PrintServer..ctor()
namespace System.Printing info ...
#region Assembly System.Printing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Printing.dll
#endregion

Categories