If have the following code:
File.Copy(@"c:\temp\test1.txt", @"c:\temp\test2.txt", true);
and it fails with:
System.IO.IOException: 'The parameter is incorrect. : 'c:\temp\test2.txt''
Both files exist. The error only occurs when targeting .NET 6 or higher. When targeting .NET Framework 4.6 (or any other framework version) the same code succeeds. I found that File.Copy uses another implementation in .NET as it has in .NET Framework.
I also found, that using cmd and using
C:\temp>xcopy test1.txt test2.txt*
also fails, with the same error:
File creation error - The parameter is incorrect.
So I am wondering if there might be something wrong in my system (Win 11 Enterprise, 21H2). Anyone any idea what might cause this problem?
File-System is formated in NTFS.
EDIT:
My problem has gotten worse now. It now also fails in .NET Framework 4.6 and higher:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Win32.Win32Native.CopyFile(String src, String dst, Boolean failIfExists)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
When debugging, I now get an Exception:
Managed Debugging Assistant 'FatalExecutionEngineError' : 'The runtime has encountered a fatal error. The address of the error was at 0x030d2887, on thread 0x52bc. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.'
And its still just the same one line of code