DLL does not load Dynamically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RSS

    #1

    DLL does not load Dynamically

    Hi everyone,
    I have an app that uses some DLL's that are shared across couple applications. There are reasons existing that prevent me from putting them in to the GAC.

    Each of these app's at some point in time loads a DLL dynamically in this fashion:

    System.Reflecti on.Assembly assembly = null;

    assembly = System.Reflecti on.Assembly.Loa dFrom(_assembly Path);

    return assembly.Create Instance(_typeN ame, false, System.Reflecti on.BindingFlags .Default, null, args, null, null);



    _assemblyPath - DB driven that has a value for path. Now, if I have a path like this "C:\Mypath\My.d ll" everything works fine. If I only have "My.dll" i get an error message saying the My.dll or one of its dependencies cannot be found. The exe and My.dll reside in the same folder and by default it should load when _assemblyPath = My.dll.





    Any idea why its not working.

    thanks a lot in advance.

  • AMDRIT

    #2
    Re: DLL does not load Dynamically

    Try ".\\" + _assemblyPath;
    "RSS" <q> wrote in message news:%235F%23Dd iaGHA.1812@TK2M SFTNGP04.phx.gb l...
    Hi everyone,
    I have an app that uses some DLL's that are shared across couple applications. There are reasons existing that prevent me from putting them in to the GAC.

    Each of these app's at some point in time loads a DLL dynamically in this fashion:

    System.Reflecti on.Assembly assembly = null;

    assembly = System.Reflecti on.Assembly.Loa dFrom(_assembly Path);

    return assembly.Create Instance(_typeN ame, false, System.Reflecti on.BindingFlags .Default, null, args, null, null);



    _assemblyPath - DB driven that has a value for path. Now, if I have a path like this "C:\Mypath\My.d ll" everything works fine. If I only have "My.dll" i get an error message saying the My.dll or one of its dependencies cannot be found. The exe and My.dll reside in the same folder and by default it should load when _assemblyPath = My.dll.





    Any idea why its not working.

    thanks a lot in advance.

    Comment

    • Bruce Wood

      #3
      Re: DLL does not load Dynamically

      Just a stab in the dark... when you start the application, what is the
      "Start in" current directory?

      If you're running from a CMD command line, do you switch directories to
      C:\Mypath and then run the app, or run it from wherever the current
      directory is?

      If you're running it from a desktop shortcut, what is your "Start in"
      path set to?

      I would assume that Assembly.LoadFr om would attempt to load from the
      current directory if no path is specified, which may not be the same as
      the directory where the executing assembly resides.

      If you always want the latter behaviour, have you tried getting the
      location of the running assembly using

      string exePath = Assembly.GetExe cutingAssembly( ).Location;

      and then building the DLL name like this:

      string dllPath = Path.Combine(Pa th.Combine(Path .GetPathRoot(ex ePath),
      Path.GetDirecto ryName(exePath) ), "My.dll");

      ?

      Comment

      • Willy Denoyette [MVP]

        #4
        Re: DLL does not load Dynamically

        Please post the exact exception message.

        Willy.

        "RSS" <q> wrote in message news:%235F%23Dd iaGHA.1812@TK2M SFTNGP04.phx.gb l...
        Hi everyone,
        I have an app that uses some DLL's that are shared across couple applications. There are reasons existing that prevent me from putting them in to the GAC.

        Each of these app's at some point in time loads a DLL dynamically in this fashion:

        System.Reflecti on.Assembly assembly = null;

        assembly = System.Reflecti on.Assembly.Loa dFrom(_assembly Path);

        return assembly.Create Instance(_typeN ame, false, System.Reflecti on.BindingFlags .Default, null, args, null, null);



        _assemblyPath - DB driven that has a value for path. Now, if I have a path like this "C:\Mypath\My.d ll" everything works fine. If I only have "My.dll" i get an error message saying the My.dll or one of its dependencies cannot be found. The exe and My.dll reside in the same folder and by default it should load when _assemblyPath = My.dll.





        Any idea why its not working.

        thanks a lot in advance.

        Comment

        • RSS

          #5
          Re: DLL does not load Dynamically

          An unexpected exception was handled while processing job requests.

          System.IO.FileN otFoundExceptio n: File or assembly name My.Core.dll, or one of its dependencies, was not found.

          File name: "My.Core.dl l"

          at System.Reflecti on.Assembly.nLo ad(AssemblyName fileName, String codeBase, Boolean isStringized, Evidence assemblySecurit y, Boolean throwOnFileNotF ound, Assembly locationHint, StackCrawlMark& stackMark)

          at System.Reflecti on.Assembly.Int ernalLoad(Assem blyName assemblyRef, Boolean stringized, Evidence assemblySecurit y, StackCrawlMark& stackMark)

          at System.Reflecti on.Assembly.Loa dFrom(String assemblyFile, Evidence securityEvidenc e, Byte[] hashValue, AssemblyHashAlg orithm hashAlgorithm)

          at System.Activato r.CreateInstanc eFrom(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttri butes, Evidence securityInfo)

          at My.Core.Typing. TypeDef.Instanc e(IDataReader dr)

          at My.Core.Typing. Type.CacheType( String typeName)

          at My.Core.Typing. Type.GetById(St ring typeName, Int32 typeId)

          at My.Core.Activit ies.ActivityTyp e.GetById(Int32 id)

          at My.Core.Activit ies.Activity.Li st(IDbConnectio n connection)

          at My.Scheduling.S chedulingServer .Version2Proces sing()

          at My.Scheduling.S chedulingServer .ProcessingLoop (Object stateInfo)

          === Pre-bind state information ===

          LOG: Where-ref bind. Location = C:\WINDOWS\syst em32\My.Core.dl l

          LOG: Appbase = c:\program files\Mine\sche duleingsetup\

          LOG: Initial PrivatePath = NULL

          Calling assembly : (Unknown).

          ===

          LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).

          LOG: Attempting download of new URL file:///C:/WINDOWS/system32/My.Core.dll.



          "Willy Denoyette [MVP]" <willy.denoyett e@telenet.be> wrote in message news:OH2swmiaGH A.4772@TK2MSFTN GP05.phx.gbl...
          Please post the exact exception message.

          Willy.

          "RSS" <q> wrote in message news:%235F%23Dd iaGHA.1812@TK2M SFTNGP04.phx.gb l...
          Hi everyone,
          I have an app that uses some DLL's that are shared across couple applications. There are reasons existing that prevent me from putting them in to the GAC.

          Each of these app's at some point in time loads a DLL dynamically in this fashion:

          System.Reflecti on.Assembly assembly = null;

          assembly = System.Reflecti on.Assembly.Loa dFrom(_assembly Path);

          return assembly.Create Instance(_typeN ame, false, System.Reflecti on.BindingFlags .Default, null, args, null, null);



          _assemblyPath - DB driven that has a value for path. Now, if I have a path like this "C:\Mypath\My.d ll" everything works fine. If I only have "My.dll" i get an error message saying the My.dll or one of its dependencies cannot be found. The exe and My.dll reside in the same folder and by default it should load when _assemblyPath = My.dll.





          Any idea why its not working.

          thanks a lot in advance.

          Comment

          • .neter

            #6
            Re: DLL does not load Dynamically

            RSS wrote:[color=blue]
            > An unexpected exception was handled while processing job requests.[/color]
            (...)

            It is looking for the file in C:\windows\syst em32. Is your program a
            windows service?
            You might try the trick with Assembly.GetExe cutingAssembly( ).Location
            posted above.

            Comment

            • RSS

              #7
              Re: DLL does not load Dynamically

              Yes it is a windows service


              ".neter" <gwrafal@poczta .onet.pl> wrote in message
              news:e2sois$s38 $1@news.onet.pl ...[color=blue]
              > RSS wrote:[color=green]
              >> An unexpected exception was handled while processing job requests.[/color]
              > (...)
              >
              > It is looking for the file in C:\windows\syst em32. Is your program a
              > windows service?
              > You might try the trick with Assembly.GetExe cutingAssembly( ).Location
              > posted above.[/color]


              Comment

              • adi

                #8
                Re: DLL does not load Dynamically

                hi,

                the "best" solution (only my opinion)

                1) keep the interfaces of your libs compatible => signatures of public
                props+methods
                (the best is only 1 version of your lib in gac + publisher policy)

                2) deploy your libs in the GAC, but only with publisher policies!
                this will redirect your "old" clients to the new versions of your libs

                loading manualy your libs may not be good for the code maintenance of
                your libs ...

                adrian

                Comment

                Working...