Object reference not set to an instance of an object. when accessed across the network but works fine locally

StackOverflow https://stackoverflow.com/questions/22645357

Pergunta

I've got an issue I can't seem to figure out and I'm spinning my wheels...I've got a project (C# multithreaded windows app) that was built as a whole and I've been tasked with breaking out the individual components to break the inter-dependencies. All the components are now broken out and I'm testing and debugging the issues I come up with before releasing it to the QA. Here is (hopefully) the last issue:

When I run the main component and it accepts a task for it to handle, it instantiates the runtime component (.DLL) which in turn instantiates an assembly (data acquisition .DLL). The assembly (data acquisition .DLL) is built around a base component which controls it's functionality. The assembly is compiled and stored on the network and accessed from there as there are multiple instances of the main component running on different machines across the network. When I attempt to access the assembly in its' directory, I get an 'Object reference not set to an instance of an object.'...BUT...when I run the same assembly, copied locally, it runs fine.

I'm at a loss as to why it runs locally but not across the net. I can't figure out where my missing reference is...Please help!!

Hopefully I've described the issue in enough detail for some guidance, if you need more detail just let me know.

EDIT: Including the code snippit and log file snippet.

Here is the section of code where the issue is happening:

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);
            }

Here is the log file of when I run it:

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

As you can see by the log, when I run it as is it get's the error. while the Application is still running (in the Debugger) I overwrite the path to my local and and it works.

EDIT: Here is the code from the Base 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);
    }
Foi útil?

Solução

Solved my issue...

I switched from using Assembly.LoadFrom() and passing the fully qualified path to Assembly.Load() and passing the bite array of the 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);

Stumbled across this in the answer to the following question: Load a dll from shared network drive in C#

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top