Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Dll References and Dependencies

Dll References and Dependencies

Scheduled Pinned Locked Moved C#
csharpwinformshelpquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MarkB123
    wrote on last edited by
    #1

    Hi, I have the following issue with my WinForms C# project and wonder if someone could point me to a solution... I have a reference to a 3rd party DLL (which I am charged for and is licensed on a per end-user basis). The dll allows me to run certain functionality within my project. Ideally I'd like to to check if the Licence file \ DLL exists (I can do this) then if it exists, proceed as normal, but if it doesn't exists, then remove access to the functionality the Dll provides. The issue I have is that I have references in the project to the DLL, so if the licence file is not there or the DLL file is not present, the app explodes on startup. Is there any way I can get around this issue? Many thanks.

    Richard Andrew x64R P B 3 Replies Last reply
    0
    • M MarkB123

      Hi, I have the following issue with my WinForms C# project and wonder if someone could point me to a solution... I have a reference to a 3rd party DLL (which I am charged for and is licensed on a per end-user basis). The dll allows me to run certain functionality within my project. Ideally I'd like to to check if the Licence file \ DLL exists (I can do this) then if it exists, proceed as normal, but if it doesn't exists, then remove access to the functionality the Dll provides. The issue I have is that I have references in the project to the DLL, so if the licence file is not there or the DLL file is not present, the app explodes on startup. Is there any way I can get around this issue? Many thanks.

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Good question. I found this article: Loading an Assembly[^] If that doesn't solve the problem, you can dynamically load the assembly with the Assembly.Load[^] method, and then create objects from it with the Activator.CreateInstance[^] method. This will allow you to remove the static reference from your project. Also, see this article about early and late binding: Early and Late Binding[^] EDIT: I apologize, that article is about VB. But if you search on "Late Binding C#" you'll find good information.

      The difficult we do right away... ...the impossible takes slightly longer.

      M 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        Good question. I found this article: Loading an Assembly[^] If that doesn't solve the problem, you can dynamically load the assembly with the Assembly.Load[^] method, and then create objects from it with the Activator.CreateInstance[^] method. This will allow you to remove the static reference from your project. Also, see this article about early and late binding: Early and Late Binding[^] EDIT: I apologize, that article is about VB. But if you search on "Late Binding C#" you'll find good information.

        The difficult we do right away... ...the impossible takes slightly longer.

        M Offline
        M Offline
        MarkB123
        wrote on last edited by
        #3

        Richard, many thanks for taking the time to reply. I'll check out the links you kindly posted.

        1 Reply Last reply
        0
        • M MarkB123

          Hi, I have the following issue with my WinForms C# project and wonder if someone could point me to a solution... I have a reference to a 3rd party DLL (which I am charged for and is licensed on a per end-user basis). The dll allows me to run certain functionality within my project. Ideally I'd like to to check if the Licence file \ DLL exists (I can do this) then if it exists, proceed as normal, but if it doesn't exists, then remove access to the functionality the Dll provides. The issue I have is that I have references in the project to the DLL, so if the licence file is not there or the DLL file is not present, the app explodes on startup. Is there any way I can get around this issue? Many thanks.

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          What I would do is have the functionality declared in an external assembly - the classes I wanted would implement interfaces stored in a DLL or the Exe and I would then use MEF to wire things together. This would allow you to use the interface as your type in the main program.

          Richard Andrew x64R 1 Reply Last reply
          0
          • P Pete OHanlon

            What I would do is have the functionality declared in an external assembly - the classes I wanted would implement interfaces stored in a DLL or the Exe and I would then use MEF to wire things together. This would allow you to use the interface as your type in the main program.

            Richard Andrew x64R Offline
            Richard Andrew x64R Offline
            Richard Andrew x64
            wrote on last edited by
            #5

            MEF? :confused:

            The difficult we do right away... ...the impossible takes slightly longer.

            M 1 Reply Last reply
            0
            • Richard Andrew x64R Richard Andrew x64

              MEF? :confused:

              The difficult we do right away... ...the impossible takes slightly longer.

              M Offline
              M Offline
              Matt T Heffron
              wrote on last edited by
              #6

              Managed Extensibility Framework[^] Wonderful magic!

              1 Reply Last reply
              0
              • M MarkB123

                Hi, I have the following issue with my WinForms C# project and wonder if someone could point me to a solution... I have a reference to a 3rd party DLL (which I am charged for and is licensed on a per end-user basis). The dll allows me to run certain functionality within my project. Ideally I'd like to to check if the Licence file \ DLL exists (I can do this) then if it exists, proceed as normal, but if it doesn't exists, then remove access to the functionality the Dll provides. The issue I have is that I have references in the project to the DLL, so if the licence file is not there or the DLL file is not present, the app explodes on startup. Is there any way I can get around this issue? Many thanks.

                B Offline
                B Offline
                BobJanova
                wrote on last edited by
                #7

                You can actually catch the exception that gets thrown when a class can't be loaded. The trick is that the class must not be used in your Main method, because entering a method which uses a class the point that the class binder tries to load it, and you can't catch it. So you can do something like

                static void Main() {
                try { EntryPoint(); }
                catch(FileNotFoundException) {
                // ...
                // e.g. put up message that a dependency is missing
                }
                }

                static void EntryPoint() {
                var x = new DependencyClass(); // declared in other assembly
                }

                The 'correct' way to do it is to handle Application.AssemblyResolve but what I've described here can be useful if all you want to do is tell the user they need to install something which is missing in a more graceful way.

                M 1 Reply Last reply
                0
                • B BobJanova

                  You can actually catch the exception that gets thrown when a class can't be loaded. The trick is that the class must not be used in your Main method, because entering a method which uses a class the point that the class binder tries to load it, and you can't catch it. So you can do something like

                  static void Main() {
                  try { EntryPoint(); }
                  catch(FileNotFoundException) {
                  // ...
                  // e.g. put up message that a dependency is missing
                  }
                  }

                  static void EntryPoint() {
                  var x = new DependencyClass(); // declared in other assembly
                  }

                  The 'correct' way to do it is to handle Application.AssemblyResolve but what I've described here can be useful if all you want to do is tell the user they need to install something which is missing in a more graceful way.

                  M Offline
                  M Offline
                  MarkB123
                  wrote on last edited by
                  #8

                  Thanks BobJanova, this might be all I need.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups