C#应用程序出错。 System.ArgumentException:路径不是合法形式?

时间:2017-12-28 06:40:32

标签: c# visual-studio

我不明白为什么这个错误即将到来我在网上搜索并且无法得到答案。 技术使用:C#
用于调试项目的Visual Studio

我有一个代码

 private void InitializeWatcher(string sourceDirectoryPath, string watcherFilter, bool isWatcherIncludeSubdirectories)
        {
            objWatcher = new FileSystemWatcher();
            objWatcher.IncludeSubdirectories =isWatcherIncludeSubdirectories;
            objWatcher.InternalBufferSize = 16384;

            if (Utilities.LogLevel >= Utilities.Informational)
            {
                Utilities.LogMessage("InitializeWatcher: " + sourceDirectoryPath, EventLogEntryType.Information);
            }
            System.Console.WriteLine( "sjdakdjasdhas ");
            System.Console.WriteLine( sourceDirectoryPath);
            objWatcher.Path = sourceDirectoryPath;
            objWatcher.Filter = watcherFilter;
            objWatcher.Created += new FileSystemEventHandler(objWatcher_FileSystemEvent);
            objWatcher.Changed += new FileSystemEventHandler(objWatcher_FileSystemEvent);
            objWatcher.Deleted += new FileSystemEventHandler(objWatcher_FileSystemEvent);
            objWatcher.Error += new ErrorEventHandler(objWatcher_Error);
            try
            {
                objWatcher.EnableRaisingEvents = true;
            }
            catch (Exception camp)
            {
                System.Console.WriteLine("camp -->");
                System.Console.WriteLine(camp);
            }
            FileSystemEventArgs objFileSystemEventArgs = new FileSystemEventArgs(WatcherChangeTypes.Changed, objWatcher.Path+"\\","\\");
            objWatcher_FileSystemEvent(objWatcher, objFileSystemEventArgs);
            watcherQueue.Add(objWatcher);
        }

运行代码时会出现错误。

sjdakdjasdhas 
\\10.197.132.58\share1
camp -->
System.ArgumentException: The path is not of a legal form.
   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.IO.FileSystemWatcher.StartRaisingEvents()
   at System.IO.FileSystemWatcher.set_EnableRaisingEvents(Boolean value)
   at xyzprojectpath.FileSystemWatcherWrapper.InitializeWatcher(String sourceDirectoryPath, String watcherFilter, Boolean isWatcherIncludeSubdirectories) in xyzpath\FileSystemWatcherWrapper.cs:line 123

有任何帮助吗?我不太了解.NET。如果需要更多代码,请告诉我。

此行出现错误

objWatcher.EnableRaisingEvents = true;

0 个答案:

没有答案