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 reference problem

Dll reference problem

Scheduled Pinned Locked Moved C#
csharphelptutorial
11 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.
  • V Offline
    V Offline
    vamsimohan21
    wrote on last edited by
    #1

    I have only one c# file (there is no solution file it's just a class file),here please tell me how to add a reference for a dll during runtime

    Thank In Advance

    S 1 Reply Last reply
    0
    • V vamsimohan21

      I have only one c# file (there is no solution file it's just a class file),here please tell me how to add a reference for a dll during runtime

      Thank In Advance

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      vamsimohan21 wrote:

      I have only one c# file (there is no solution file it's just a class file),

      only one .cs file No solution or Project file ?

      vamsimohan21 wrote:

      here please tell me how to add a reference for a dll during runtime

      You want o add dll for a dll ? or you want add dll to 1 .cs file ?

      Thanks and Regards Sandeep If you want something you never had, do something you have never done!

      V 1 Reply Last reply
      0
      • S Sandeep Akhare

        vamsimohan21 wrote:

        I have only one c# file (there is no solution file it's just a class file),

        only one .cs file No solution or Project file ?

        vamsimohan21 wrote:

        here please tell me how to add a reference for a dll during runtime

        You want o add dll for a dll ? or you want add dll to 1 .cs file ?

        Thanks and Regards Sandeep If you want something you never had, do something you have never done!

        V Offline
        V Offline
        vamsimohan21
        wrote on last edited by
        #3

        I want to add another external dll to this file for example add.dll to this file test.cs

        ALL THE BEST

        S A 2 Replies Last reply
        0
        • V vamsimohan21

          I want to add another external dll to this file for example add.dll to this file test.cs

          ALL THE BEST

          A Offline
          A Offline
          AFSEKI
          wrote on last edited by
          #4

          You can not add a reference in a class library project to another dll at run-time because there will never be a run time for a class library, it is not executable. Of course depending on your level, you can make a dll to run as a standalone application with Rundll or Rundll32 commands from Windows to run functions in your class library(mylib.dll). In this scenario, you can add a "reference" by calling Assembly.Load(...), Assembly.LoadFile(...) or Assembly.LoadFrom(...) methods available in System.Reflection namespace. If you want to copy a dll to your working folder and then add a reference to it, then you can use File.Copy or File.Move functions in System.IO namespace. I hope this helps you friend.

          V C 2 Replies Last reply
          0
          • V vamsimohan21

            I want to add another external dll to this file for example add.dll to this file test.cs

            ALL THE BEST

            S Offline
            S Offline
            Sandeep Akhare
            wrote on last edited by
            #5

            I think you can't do that as it is only a CS file. by the way what you want to achieve by doing this ?

            Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

            1 Reply Last reply
            0
            • A AFSEKI

              You can not add a reference in a class library project to another dll at run-time because there will never be a run time for a class library, it is not executable. Of course depending on your level, you can make a dll to run as a standalone application with Rundll or Rundll32 commands from Windows to run functions in your class library(mylib.dll). In this scenario, you can add a "reference" by calling Assembly.Load(...), Assembly.LoadFile(...) or Assembly.LoadFrom(...) methods available in System.Reflection namespace. If you want to copy a dll to your working folder and then add a reference to it, then you can use File.Copy or File.Move functions in System.IO namespace. I hope this helps you friend.

              V Offline
              V Offline
              vamsimohan21
              wrote on last edited by
              #6

              Thank you so much for the response guys. Here below is the peice of code which i tried it but failed :-( Assembly SampleAssembly; System.Reflection.AssemblyName objName = new AssemblyName(); objName.CodeBase = "D:\\Debug\\Utilities.EncryptParm.dll"; SampleAssembly = Assembly.Load(objName); Type[] Types = SampleAssembly.GetTypes(); foreach (Type oType in Types) { Console.WriteLine(oType.Name.ToString()); if(oType.Name == "EncryptParm") { string[] encryptValues = {"4865","78043","GABRIELEZZ"}; string encryptKey = "CF2ASP?73ejb01"; Utilities.EncryptParm encryptor = new Utilities.EncryptParm(); string encryptedId = encryptor.Encrypt( encryptKey, encryptValues); Console.WriteLine(encryptedId); Console.ReadLine(); } } Please rectify me for any correction

              Thanks In Advance

              A A 2 Replies Last reply
              0
              • V vamsimohan21

                Thank you so much for the response guys. Here below is the peice of code which i tried it but failed :-( Assembly SampleAssembly; System.Reflection.AssemblyName objName = new AssemblyName(); objName.CodeBase = "D:\\Debug\\Utilities.EncryptParm.dll"; SampleAssembly = Assembly.Load(objName); Type[] Types = SampleAssembly.GetTypes(); foreach (Type oType in Types) { Console.WriteLine(oType.Name.ToString()); if(oType.Name == "EncryptParm") { string[] encryptValues = {"4865","78043","GABRIELEZZ"}; string encryptKey = "CF2ASP?73ejb01"; Utilities.EncryptParm encryptor = new Utilities.EncryptParm(); string encryptedId = encryptor.Encrypt( encryptKey, encryptValues); Console.WriteLine(encryptedId); Console.ReadLine(); } } Please rectify me for any correction

                Thanks In Advance

                A Offline
                A Offline
                andre_swnpl
                wrote on last edited by
                #7

                vamsimohan21 wrote:

                Utilities.EncryptParm encryptor = new Utilities.EncryptParm(); string encryptedId = encryptor.Encrypt( encryptKey, encryptValues);

                You cannot execute this when you have loaded the assembly by using Assembly.Load. You have to call InvokeMember(...) instead. Hope this helps.

                1 Reply Last reply
                0
                • A AFSEKI

                  You can not add a reference in a class library project to another dll at run-time because there will never be a run time for a class library, it is not executable. Of course depending on your level, you can make a dll to run as a standalone application with Rundll or Rundll32 commands from Windows to run functions in your class library(mylib.dll). In this scenario, you can add a "reference" by calling Assembly.Load(...), Assembly.LoadFile(...) or Assembly.LoadFrom(...) methods available in System.Reflection namespace. If you want to copy a dll to your working folder and then add a reference to it, then you can use File.Copy or File.Move functions in System.IO namespace. I hope this helps you friend.

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #8

                  AFSEKI wrote:

                  there will never be a run time for a class library, it is not executable.

                  Yes, it is! It isn't directly executable, it requires something else to form the process for it, but a class library is as executable as any other .NET code.


                  Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

                  A 1 Reply Last reply
                  0
                  • V vamsimohan21

                    Thank you so much for the response guys. Here below is the peice of code which i tried it but failed :-( Assembly SampleAssembly; System.Reflection.AssemblyName objName = new AssemblyName(); objName.CodeBase = "D:\\Debug\\Utilities.EncryptParm.dll"; SampleAssembly = Assembly.Load(objName); Type[] Types = SampleAssembly.GetTypes(); foreach (Type oType in Types) { Console.WriteLine(oType.Name.ToString()); if(oType.Name == "EncryptParm") { string[] encryptValues = {"4865","78043","GABRIELEZZ"}; string encryptKey = "CF2ASP?73ejb01"; Utilities.EncryptParm encryptor = new Utilities.EncryptParm(); string encryptedId = encryptor.Encrypt( encryptKey, encryptValues); Console.WriteLine(encryptedId); Console.ReadLine(); } } Please rectify me for any correction

                    Thanks In Advance

                    A Offline
                    A Offline
                    AFSEKI
                    wrote on last edited by
                    #9

                    YOU HAVE NOT READ MY PREVIOUS ANSWER TO YOUR QUESTION, BUT I SEND YOU A NEW ONE FOR THE LAST TIME Use below code: string assemblyFullPath = @"C:\myAssembly.dll"; Assembly workerAssembly = LoadAssembly(assemblyFullPath); Type[] types = workerAssembly.GetTypes(); foreach (Type oType in types) { Console.WriteLine(oType.Name.ToString()); if(oType.Name == "EncryptParm") { string[] encryptValues = {"4865","78043","GABRIELEZZ"}; string encryptKey = "CF2ASP?73ejb01"; Utilities.EncryptParm encryptor = new Utilities.EncryptParm(); string encryptedId = encryptor.Encrypt( encryptKey, encryptValues); Console.WriteLine(encryptedId); Console.ReadLine(); } }

                    1 Reply Last reply
                    0
                    • C Colin Angus Mackay

                      AFSEKI wrote:

                      there will never be a run time for a class library, it is not executable.

                      Yes, it is! It isn't directly executable, it requires something else to form the process for it, but a class library is as executable as any other .NET code.


                      Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

                      A Offline
                      A Offline
                      AFSEKI
                      wrote on last edited by
                      #10

                      If you read my post completely not only 1 sentence of it you could see that I tell how a dll can be run. You are a very excited young boy he? ;)

                      C 1 Reply Last reply
                      0
                      • A AFSEKI

                        If you read my post completely not only 1 sentence of it you could see that I tell how a dll can be run. You are a very excited young boy he? ;)

                        C Offline
                        C Offline
                        Colin Angus Mackay
                        wrote on last edited by
                        #11

                        AFSEKI wrote:

                        If you read my post completely not only 1 sentence of it you could see that I tell how a dll can be run.

                        I did read your entire post. The latter part of your post contradicted the former part. I clarified it.

                        AFSEKI wrote:

                        You are a very excited young boy he?

                        I'm neither young, nor exited. I'm old and grumpy. ;P


                        Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

                        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