未设置为对象实例的对象引用.当通过网络访问时,但在本地工作良好
本文关键字:工作 访问 网络 实例 对象 设置 对象引用 | 更新日期: 2023-09-27 17:53:07
我有一个问题,我似乎不能弄清楚,我在旋转我的轮子…我有一个项目(c#多线程windows应用程序),它是作为一个整体构建的,我的任务是打破单个组件来打破相互依赖关系。现在所有的组件都被分解了,我正在测试和调试我提出的问题,然后将其发布给QA。这是(希望)最后一个问题:
当我运行主组件时,它接受一个任务来处理,它实例化运行时组件(. dll),然后实例化一个程序集(数据采集. dll)。程序集(数据采集. dll)是围绕控制其功能的基本组件构建的。程序集被编译并存储在网络上,并从网络上访问,因为在网络上的不同机器上运行着主组件的多个实例。当我试图访问其目录中的程序集时,我得到一个"对象引用未设置为对象的实例"…但是…当我运行本地复制的相同程序集时,它运行良好。
我不知道为什么它在本地运行而不是在整个网络上运行。我想不出我丢失的参考资料在哪里了。请帮助! !
希望我已经足够详细地描述了这个问题,为一些指导,如果你需要更多的细节,请告诉我。
编辑:包括代码片段和日志文件片段。
下面是发生问题的代码段:
string assemblyName = moduleName;
_log.LogMessage("DACLRuntime assemblyName: " + assemblyName);
Assembly dacAssembly = Assembly.LoadFrom(assemblyName);
moduleName = Path.GetFileNameWithoutExtension(assemblyName);
_log.LogMessage("DACLRuntime moduleName: " + moduleName);
var dacType = (from c in dacAssembly.GetTypes() where c.Name.EqualsIgnoreCase(moduleName) select c).First();
_log.LogMessage("DACLRuntime dacType: " + dacType.ToString());
if (dacType != null)
{
_log.LogMessage("DACLRuntime Instansiate the DACBase...");
DACBase dac = (DACBase)Activator.CreateInstance(dacType);
_log.LogMessage("DACLRuntime DACBase is instantiated...");
dac.gsDACLPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
_log.LogMessage("DACBase path is: " + dac.gsDACLPath);
try
{
// -- Does the script exist...
if (File.Exists(assemblyName))
_log.LogMessage("Script located at ==> " + assemblyName + " <== Exists.");
_log.LogMessage("Script Started:" + assemblyName + " orderid:" + orderId);
dac.iPid = iPid;
_log.LogMessage(" dac.iPid = " + iPid.ToString());
_log.LogMessage(" Calling dac.InitAndExecute()...Passing the OrderId and the RunTime Log file (_log)...");
dac.InitAndExecute(orderId, _log);
_log.LogMessage(" Call to dac.InitAndExecute() sucessful...");
}
catch (IndexOutOfRangeException)
{
// Coded As per ZAM to raise error 17 if it is index out of bounds
dac.Frame.Error = 17;
_log.LogInformation("Index was outside the bounds of the array For " + assemblyName + " orderid:" + orderId);
}
下面是我运行它时的日志文件:
3/25/2014 12:23:15:490 PM *
3/25/2014 12:23:15:490 PM *
3/25/2014 12:23:15:490 PM *
3/25/2014 12:23:15:490 PM DACLRuntime LogFile: DACLRuntime20140325.Log
3/25/2014 12:23:15:490 PM DACLRuntime: C:'FS2000_V2'DACLRuntime.exe
3/25/2014 12:23:15:490 PM DACLRuntime Started: 3/25/2014 12:23:15 PM
3/25/2014 12:23:15:506 PM DACLRuntime assemblyName: ''fshqsna09vfs98 'DEV'DACLScripts'FARES_VL.dll
3/25/2014 12:23:15:615 PM DACLRuntime moduleName: FARES_VL
3/25/2014 12:23:15:615 PM DACLRuntime dacType: FS.DACL.AnyCounty.FARES_VL
3/25/2014 12:23:15:615 PM DACLRuntime Instansiate the DACBase...
3/25/2014 12:23:15:615 PM DACLRuntime DACBase is instantiated...
3/25/2014 12:23:15:630 PM DACBase path is: C:'FS2000_V2
3/25/2014 12:23:15:630 PM Script located at ==> ''fshqsna09vfs98 'DEV'DACLScripts'FARES_VL.dll <== Exists.
3/25/2014 12:23:15:630 PM Script Started:''fshqsna09vfs98'DEV'DACLScripts'FARES_VL.dll orderid:15089333F 42
3/25/2014 12:23:15:630 PM dac.iPid = 1
3/25/2014 12:23:15:630 PM Calling dac.InitAndExecute()...Passing the OrderId and the RunTime Log file (_log)...
3/25/2014 12:23:15:630 PM DACLRuntime Logging Passed in...
3/25/2014 12:23:15:630 PM DACLRuntime20140325.Log
3/25/2014 12:23:15:630 PM Calling the Initialize()...
3/25/2014 12:23:15:662 PM [DEBUGGING] ::: DACLBase :: InitAndExecute : Setting the OrderId...
3/25/2014 12:23:15:662 PM [DEBUGGING] ::: DACLBase :: InitAndExecute : Entering Script...
3/25/2014 12:23:16:161 PM [ERROR], Object reference not set to an instance of an object. { at FS.DACL.AnyCounty.FARES_VL.Script_Exit()
at FS.DACL.Tag.Tag.PopulateTagList(String sOrigin)
at FS.DACL.NamesToRun.NamesToRun..ctor(DACBase scriptDAC)
at FS.DACL.AnyCounty.FARES_VL.Main(String sOrder)
at FS.DACL.AnyCounty.FARES_VL.Main(Object[] parameters)
at FS.DACL.Base.DACBase.InitAndExecute(Object[] args) in c:'FASTSearch'Dev'FeatInt'Source'DACL_V2'Feature1_DACL'DACLBase'DACBase.cs:line 392
at FS.DACL.Runtime.Program.RunDACLModule(String[] args) in c:'FASTSearch'Dev'FeatInt'Source'DACL_V2'Feature1_DACLRuntime'Program.cs:line 122}
3/25/2014 12:23:16:161 PM SessionKill- fsSession || gSession is null 15089333F 42 0
3/25/2014 12:23:16:161 PM Recreating channel at fsSession SessionKill
3/25/2014 12:23:16:816 PM Script : ''fshqsna09vfs98'DEV'DACLScripts'FARES_VL.dll orderid:15089333F 42 : RunResult 15
3/25/2014 12:23:35:425 PM *
3/25/2014 12:23:35:441 PM *
3/25/2014 12:23:35:441 PM *
3/25/2014 12:23:35:441 PM DACLRuntime LogFile: DACLRuntime20140325.Log
3/25/2014 12:23:35:441 PM DACLRuntime: C:'FS2000_V2'DACLRuntime.exe
3/25/2014 12:23:35:441 PM DACLRuntime Started: 3/25/2014 12:23:35 PM
3/25/2014 12:23:35:441 PM DACLRuntime assemblyName: C:'Work'Test Scrapes Current Dev'FARES_VL.dll
3/25/2014 12:23:35:441 PM DACLRuntime moduleName: FARES_VL
3/25/2014 12:23:35:441 PM DACLRuntime dacType: FS.DACL.AnyCounty.FARES_VL
3/25/2014 12:23:35:456 PM DACLRuntime Instansiate the DACBase...
3/25/2014 12:23:35:456 PM DACLRuntime DACBase is instantiated...
3/25/2014 12:23:35:456 PM DACBase path is: C:'FS2000_V2
3/25/2014 12:23:35:456 PM Script located at ==> C:'Work'Test Scrapes Current Dev'FARES_VL.dll <== Exists.
3/25/2014 12:23:35:456 PM Script Started:C:'Work'Test Scrapes Current Dev'FARES_VL.dll orderid:15089333F 42
3/25/2014 12:23:35:456 PM dac.iPid = 2
3/25/2014 12:23:35:456 PM Calling dac.InitAndExecute()...Passing the OrderId and the RunTime Log file (_log)...
3/25/2014 12:23:35:456 PM DACLRuntime Logging Passed in...
3/25/2014 12:23:35:456 PM DACLRuntime20140325.Log
3/25/2014 12:23:35:456 PM Calling the Initialize()...
3/25/2014 12:23:35:456 PM DACLBase Initializing...3/25/2014 12:23:35 PM
3/25/2014 12:23:35:456 PM CommonFunctions (CF) Initializing...
3/25/2014 12:23:35:472 PM CommonRoutiness (CR) Initializing...
3/25/2014 12:23:35:472 PM DACFrame (Frame) Initializing...
3/25/2014 12:23:35:472 PM DBExtn (FSHDB) Initializing...
3/25/2014 12:23:35:472 PM [DBExtn] START: Initializing DBZ Engine parameters.
3/25/2014 12:23:35:472 PM [DBExtn] Getting parameters from the FS.DACL.RunTime.Program.cs
从日志中可以看到,当我按原样运行它时,它得到了错误。当应用程序仍在运行时(在调试器中),我将路径覆盖到我的本地和它的工作。
编辑:这是来自基本DLL的代码。
protected virtual void Initialize()
{
// - - - Initialize Logging for the application - - -
if (_log == null)
{
_log = new Logger("DACLRuntime.Log", 7);
_log.LogMessage("DACLRuntime Logging being used...");
}
_log.LogMessage("DACLBase Initializing..." + DateTime.Now.ToString());
// -- Initialize the sub-components...
_log.LogMessage(" CommonFunctions (CF) Initializing...");
if (CF == null) CF = new CommonFunctions(this);
_log.LogMessage(" CommonRoutiness (CR) Initializing...");
if (CR == null) CR = new CommonRoutines(this);
_log.LogMessage(" DACFrame (Frame) Initializing...");
if (Frame == null) Frame = new DACFrame();
_log.LogMessage(" DBExtn (FSHDB) Initializing...");
if (FSDBH == null) FSDBH = new DBExtn();
// -- Log the DB initialization...
_log.LogMessage("DACL Database (FSDBH) Connected: " + FSDBH.ADOConnect("FS2000").ToString());
_log.LogMessage("[DEBUGGING] ::: DACLBase :: Initialize : ZDVR Set as:" + gsDACLPath);
}
protected abstract void Main(params object[] parameters);
public void InitAndExecute(params object[] args)
{
// -- Debugging...
if (args != null && args.Length > 0)
{
_log = (Logger)args[1];
_log.LogMessage("DACLRuntime Logging Passed in...");
_log.LogMessage(_log.CurrentLogFile);
}
_log.LogMessage("Calling the Initialize()...");
Initialize();
_log.LogMessage("[DEBUGGING] ::: DACLBase :: InitAndExecute : Setting the OrderId...");
if (args != null && args.Length > 0)
if (args[0].ToString().Trim().Length == 12)
OrderId = args[0].ToString();
// -- Debugging...
_log.LogMessage("[DEBUGGING] ::: DACLBase :: InitAndExecute : Entering Script...");
Main(args);
}
解决了我的问题…
我从使用Assembly.LoadFrom()切换到将完全限定路径传递给Assembly.Load()并传递dll的咬合数组。
_log.LogMessage("DACLRuntime assemblyName: " + assemblyName);
//Assembly dacAssembly = Assembly. loadfrom (assemblyName);
string sAssFile = assemblyName;
byte[] AssmBytes = File.ReadAllBytes(sAssFile);
Assembly dacAssembly = Assembly.Load(AssmBytes);
moduleName = Path.GetFileNameWithoutExtension(assemblyName);
在回答以下问题时偶然发现了这个问题:在c#中从共享网络驱动器加载dll