I have a jpg in a folder in my project. I want to make a bitmap out of it but it says my path is invalid when I try to refer to the jpg.
https://i.stack.imgur.com/dAWIG.jpg
Console Exception:
Unhandled Exception: System.ArgumentException: Illegal characters in path.
at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.GetFullPathInternal(String path)
at System.IO.Path.GetFullPath(String path)
at System.Drawing.IntSecurity.UnsafeGetFullPath(String fileName)
at System.Drawing.IntSecurity.DemandReadFileIO(String fileName)
at System.Drawing.Bitmap..ctor(String filename)
at ConsoleImageCompare.Compare.differance(String img1, String img2) in c:\users\user\documents\visual studio 2017\Projects\ConsoleImageCompare\ConsoleImageCompare\Compare.cs:line 22
at ConsoleImageCompare.Program.Main(String[] args)
The reason is by default console application points to the bin/debug folder.So you need to go up two level to get the file
#"../../image/<Your File name>"
Use this
Related
I'm working on a legacy project, and through debugging and re-engineering i stumbled upon the following error.
The documents are send to the location http://localhost:8080/Files
In the existing application it is handled like this
1 var path = Export.Path; <- in Debug it is `http://localhost:8080/Files`
2 Directory.SetCurrentDirectory(path);
At Line 2 the following Exception is thrown:
System.ArgumentException
HResult=-2147024809
Message=URI-Formate not supported.
Source=mscorlib
StackTrace:
in System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
in System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
in System.IO.Path.GetFullPathInternal(String path)
in System.IO.Directory.SetCurrentDirectory(String path)
in Controller.cs:Line 125.
in lambda_method(Closure , Object , Object[] )
in System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
in System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
in System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
in System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
InnerException:
The directory exists and I can access it via the url-line in the browser. I searched through multiple solutions but found nothing that fits my problem.
Hi I'm running the following code:
void bar()
{
var dirInfo = new DirectoryInfo("C:\foo\folder");
dirInfo.Delete();
}
And at one point I got the following exception:
System.IO.IOException: The process cannot access the file 'C:\foo\folder' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive)
at bar()
Two things bother me here:
I called DirectoryInfo's Delete(). Why did I get Directory's Delete() in the stack trace without DirectoryInfo's one?
How come the file that is being used has the same path as my folder? Is this an error in the message? Or was there a different error?
To answer the first of your questions, DirectoryInfo.Delete calls Directory.Delete. If you're running in release mode, it's possible the compiler has optimised your code and you're just seeing the underlying call.
Edit: I've just done some tests in VS2013. When my project was a release build compiled for Any CPU I could see the call to DirectoryInfo.Delete before the call to Directory.Delete in the stack trace:
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
at System.IO.DirectoryInfo.Delete()
at test.Program.Main(String[] args) in c:\Projects\test\Program.cs:line 21
but when I compiled a release build for x64 it showed only the call to Directory.Delete:
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive, Boolean throwOnTopLevelDirectoryNotFound)
at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive, Boolean checkHost)
at test.Program.Main(String[] args) in c:\Projects\test\Program.cs:line 22
It does look like some optimisation is going on (incidentally, the code was unchanged between tests - I'm guessing the change in line number is also related somehow to compiler optimisation).
Have a look at this question - directoryinfo delete vs directory delete
To answer your other question - did you have a file in the directory open in another app? There are many reasons why another process may be doing something to that folder.
We're using IKVM to convert our *.jar to dll that we using to migrate our code to C# with Mono..
We have a problem especially when working with jar contains a JNI call, expl JnativeHook, its make an error when we try to convert it using IKVM, i have reported the error to the author as the follow:
I'm trying to use JnativeHook.jar library, its work for my java apllications, However:
Not: JnativeHook its a cross-platform containes 3 .dll depends on the OS when the java application is running (dynamic loading of *.dll)...
JnativeHook.jar containes also a package(demo) that containes a main classe, i have solved this problem by deleting this one, now i'm sure that will be converted to dll...
finally, when i try to convert this one to .dll i get this error:
C:\Users\marwen\Desktop\Kid protector\Tools and IDE\ikvmbin-7.2.4630.5\bin>ikvmc JNativeHook.jar
IKVM.NET Compiler version 7.2.4630.5
Copyright (C) 2002-2012 Jeroen Frijters
http://www.ikvm.net/
note IKVMC0002: Output file is "JNativeHook.dll"
*** INTERNAL COMPILER ERROR ***
PLEASE FILE A BUG REPORT FOR IKVM.NET WHEN YOU SEE THIS MESSAGE
System.UnauthorizedAccessException: L'accès au chemin d'accès 'C:\Users\marwen\Desktop\Kid protector\Tools and IDE\ikvmbin-7.2.4630.5\bin\JNativeHook.dll' est refusé.
à System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
à System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, Str
ing msgPath, Boolean bFromProxy)
à System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
à System.IO.FileStream..ctor(String path, FileMode mode)
à IKVM.Reflection.Writer.ModuleWriter.WriteModule(StrongNameKeyPair keyPair, Byte[] publicKey, ModuleBuilder moduleBuilder, PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, Ima
geFileMachine imageFileMachine, ResourceSection resources, Int32 entryPointToken, Stream stream)
à IKVM.Reflection.Emit.AssemblyBuilder.SaveImpl(String assemblyFileName, Stream streamOrNull, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
à IKVM.Reflection.Emit.AssemblyBuilder.Save(String assemblyFileName, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
à IKVM.Internal.CompilerClassLoader.Save()
à IKVM.Internal.CompilerClassLoader.Compile(String runtimeAssembly, List`1 optionsList)
à IkvmcCompiler.Compile(String[] args)
à IkvmcCompiler.Main(String[] args)
The response from the author:
>Comment By: Jeroen Frijters (jfrijters)
Date: 2013-02-12 03:28
Message:
Thanks. Fixed in cvs. BTW, the error is because ikvmc can't write to
JNativeHook.dll (probably because you don't have write access to the
directory).
As you can see the author has respond with a few words without giving us a solution..
What i understand is the embedded Dll make the error, in fact IKVM does not know how to work with it(inside the JAR)...
there is some suggestions to solve this problem?
PS: what does mean Fixed in cvs ?
Thank you.
The cause of the problem is that you have no write rights to the output location. Run the command on another location with write rights.
I think the fix will only prevent the "INTERNAL COMPILER ERROR" message.
string source = #"C:\Users\damanja\Desktop\Projects\RecStudentManagement\RecStudentManagement.Web\Reports\Templates\ContactInformationReport.xlsx";
string dest = #"C:\Users\damanja\Desktop\Projects\RecStudentManagement\RecStudentManagement.Web\Reports\Ran\damanja2012-12-17T10:14:02.0394885-06:00.xlsx";
File.Copy(source, dest, true);
Produces this exception:
The given path's format is not supported.
Stack trace:
at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String[] pathList, Boolean checkForDuplicates, Boolean needFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
at RecStudentManagement.Web.Reports.ExcelReport.CopyTemplate() in C:\\Users\\damanja\\Desktop\\Projects\\RecStudentManagement\\RecStudentManagement.Web\\Reports\\ExcelReport.cs:line 52
at RecStudentManagement.Web.Reports.ExcelReport..ctor(String fileName) in C:\\Users\\damanja\\Desktop\\Projects\\RecStudentManagement\\RecStudentManagement.Web\\Reports\\ExcelReport.cs:line 35
at RecStudentManagement.Web.Reports.ContactInformationReport..ctor(IEnumerable`1 students, IEnumerable`1 includedPrograms, String createdByULID, String fileName) in C:\\Users\\damanja\\Desktop\\Projects\\RecStudentManagement\\RecStudentManagement.Web\\Reports\\ContactInformationReport.cs:line 22
at RecStudentManagement.Web.Controllers.ReportsController.ContactInformationCreate(ContactInformationSetUpViewModel vm) in C:\\Users\\damanja\\Desktop\\Projects\\RecStudentManagement\\RecStudentManagement.Web\\Controllers\\ReportsController.cs:line 99
Both the source and destination directories exist.
You have colons (:) in the destination path, which Windows does not allow (apart from as part of the drive letter specifier, of course...).
To get this to work, pick a different date format for the date-time you are trying to embed, which does not use colons.
Here is a MSDN site which will explain reserved characters as well as what is allowed or not allowed when creating Windows File Paths
replace the ":" with underscores if you have to "_" reformat the date portion as well to use yyyymmdd, or mmddyyyy stored in a different DateTime variable and convert that to a String.. there are many other options you can use..
Naming Files, Paths, and Namespaces (Windows)
I copied my project to a dsik on key and tried to run it in my mother home pc.
In my code im using HtmlAgilityPack.HtmlWeb and i have this line:
private List<string> test(string url, int levels,DoWorkEventArgs eve)
{
levels = 0;
HtmlWeb hw = new HtmlWeb();
If i run my program it will not throw any exception but will continue just will not do anything.
If i put a breakpoint on the line: HtmlWEb hw = new HtmlWeb();
Im moving to a No Source Available window:
Locating source for 'D:\Source\htmlagilitypack.new\Trunk\HtmlAgilityPack\HtmlWeb.cs'. Checksum: MD5 {58 c1 63 f6 cd 5 65 de 4c 3c d5 4b b1 b7 7 48}
The file 'D:\Source\htmlagilitypack.new\Trunk\HtmlAgilityPack\HtmlWeb.cs' does not exist.
Looking in script documents for 'D:\Source\htmlagilitypack.new\Trunk\HtmlAgilityPack\HtmlWeb.cs'...
Looking in the projects for 'D:\Source\htmlagilitypack.new\Trunk\HtmlAgilityPack\HtmlWeb.cs'.
The file was not found in a project.
I see that HtmlWeb.cs is missing in some directory on D:\
I have also a try and catch in my function test if i put a breakpoint on the catch i see:
IOexception was caught.
The device is not ready.
My guess that its looking for a file maybe HtmlWeb.cs in D:\
And in my mother pc D:\ is a DVD drive in my pc its hard disk.
The full exception:
System.IO.IOException was caught
Message=The device is not ready.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path)
at GatherLinks.Form1.removeDuplicates(List`1 a, List`1 b) in F:\GatherLinks\GatherLinks\Form1.cs:line 250
at GatherLinks.Form1.test(String url, Int32 levels, DoWorkEventArgs eve) in F:\GatherLinks\GatherLinks\Form1.cs:line 111
InnerException:
I dont see any problems in my code in the reference area with the HtmlAgilityPack.dllim
Its not missing.
So i wonder why its looking for a file on D:\ ?
If on my pc i did rebuild/build solution and saved it all i was sure its adding all the files and dll's it needs to the project so if i copy it to my disk on key and run it on my mother pc it will work.
So what did i do wrong here ? And how should i fix/repair it ?
I erased the HtmlAgilityPack.pdb and it worked just fine. Erase the file, rebuild, close and reopen and see if it works