FileSystemWatcher.Path网络共享驱动器的例外

时间:2017-05-15 09:47:42

标签: c# .net filesystemwatcher mapped-drive

我正在使用FileSystemWatcher对象来检索文件夹中的文件。

该代码适用于本地计算机驱动器/文件夹,但在使用NETWORK路径时会抛出异常。

由于某种原因,如果我在调试模式下启动服务,代码不会抛出异常。如果我通过installutil安装它,那么再次抛出此异常。 也许有一些许可问题,但我不知道是什么......

public LevelOneValidatedWatcher(string strLevelOneFolder)
{
    FileSystemWatcher objFSW = new FileSystemWatcher();
    objFSW.Path = strLevelOneFolder; /// <<<<<<<<<<<<    EXCEPTION THROWN HERE
    objFSW.Filter = "*.zip";
    objFSW.Created += new FileSystemEventHandler(myWatcher_Created);
    objFSW.Renamed += new RenamedEventHandler(mydWatcher_Renamed);
    objFSW.EnableRaisingEvents = true;
}

System.ArgumentException was unhandled
Message=The directory name T:\INFORMATION TECHNOLOGY\bu is invalid.
Source=System
StackTrace:
at System.IO.FileSystemWatcher.set_Path(String value)
at MA.BatchTool.ServerLibrary.LevelOneValidatedWatcher..ctor(String strLevelOneFolder) in D:\Dev\Projects\MailAssurety1.1\Development\SourceCode\MA_1.1\WebServerSide\WebServerLibraries\LevelOneValidatedWatacher.cs:line 23
at MA.BatchTool.ServerLibrary.ServerJobProcessor.StartFileWatcher(Object strPath) in D:\Dev\Projects\MailAssurety1.1\Development\SourceCode\MA_1.1\WebServerSide\WebServerLibraries\ServerJobProcessor.cs:line 32
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)

2 个答案:

答案 0 :(得分:1)

驱动器号映射是每个交互式登录设置。例外是告诉你实话,T:\INFORMATION TECHNOLOGY\bu确实不存在,因为对于你自己的会话以外的会话(例如服务运行的会话0),驱动器T:\不会被映射到任何地方。调试时它起作用的原因是因为在调试时你可能在自己的会话中而不是在会话0内运行服务。

当您尝试从UAC提示符启动的程序访问映射驱动器时会发生类似的问题,因为UAC用户被视为&#34;不同的用户&#34;。

可能进一步阅读潜在的解决方法&#34; Map a network drive to be used by a service&#34;

答案 1 :(得分:0)

我认为2017-05-16 08:00:03 CST ERROR: could not open relation with OID 17221405 at haracter 19 2017-05-16 08:00:03 CST QUERY: create temp table temp_powStaId(powStaId int) on commit drop 2017-05-16 08:00:03 CST QUERY: create temp table temp_powStaId(powStaId int) on commit drop 2017-05-16 08:00:03 CST CONTEXT: PL/pgSQL function fn_read_powsta_cache_by_userid(integer) line 26 at SQL statement 2017-05-16 08:00:03 CST STATEMENT: select * from fn_read_powsta_cache_by_userid($1) as result 2017-05-16 08:00:03 CST ERROR: current transaction is aborted, commands ignored until end of transaction block 2017-05-16 08:00:03 CST STATEMENT: SELECT NULL AS TABLE_CAT, n.nspname AS TABLE_SCHEM, c.relname AS TABLE_NAME, CASE n.nspname ~ '^pg_' OR n.nspname = 'information_schema' WHEN true THEN CASE WHEN n.nspname = 'pg_catalog' OR n.nspname = 'information_schema' THEN CASE c.relkind WHEN 'r' THEN 'SYSTEM TABLE' WHEN 'v' THEN 'SYSTEM VIEW' WHEN 'i' THEN 'SYSTEM INDEX' ELSE NULL END WHEN n.nspname = 'pg_toast' THEN CASE c.relkind WHEN 'r' THEN 'SYSTEM TOAST TABLE' WHEN 'i' THEN 'SYSTEM TOAST INDEX' ELSE NULL END ELSE CASE c.relkind WHEN 'r' THEN 'TEMPORARY TABLE' WHEN 'i' THEN 'TEMPORARY INDEX' WHEN 'S' THEN 'TEMPORARY SEQUENCE' WHEN 'v' THEN 'TEMPORARY VIEW' ELSE NULL END END WHEN false THEN CASE c.relkind WHEN 'r' THEN 'TABLE' WHEN 'i' THEN 'INDEX' WHEN 'S' THEN 'SEQUENCE' WHEN 'v' THEN 'VIEW' WHEN 'c' THEN 'TYPE' WHEN 'f' THEN 'FOREIGN TABLE' WHEN 'm' THEN 'MATERIALIZED VIEW' ELSE NULL END ELSE NULL END AS TABLE_TYPE, d.description AS REMARKS FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_description d ON (c.oid = d.objoid AND d.objsubid = 0) LEFT JOIN pg_catalog.pg_class dc ON (d.classoid=dc.oid AND dc.relname='pg_class') LEFT JOIN pg_catalog.pg_namespace dn ON (dn.oid=dc.relnamespace AND dn.nspname='pg_catalog') WHERE c.relnamespace = n.oid AND c.relname LIKE 'PROBABLYNOT' AND (false OR ( c.relkind = 'r' AND n.nspname !~ '^pg_' AND n.nspname <> 'information_schema' ) ) ORDER BY TABLE_TYPE,TABLE_SCHEM,TABLE_NAME 2017-05-16 09:11:00 CST ERROR: could not open relation with OID 17221405 at character 20 2017-05-16 09:11:00 CST QUERY: create temp table temp_region_partition_info_status(nodeID int, data jsonb) on commit drop 2017-05-16 09:11:00 CST CONTEXT: PL/pgSQL function fn_statistic_node_status() line 47 at SQL statement 2017-05-16 09:11:00 CST STATEMENT: begin; select fn_statistic_node_status(); commit; 2017-05-16 09:11:00 CST ERROR: current transaction is aborted, commands ignored until end of transaction block 2017-05-16 09:11:00 CST STATEMENT: RESET ALL 无法访问共享驱动器,您必须将Windows服务配置为以特定用户身份运行

picture