Dll reference problem
-
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
-
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
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!
-
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!
I want to add another external dll to this file for example add.dll to this file test.cs
ALL THE BEST
-
I want to add another external dll to this file for example add.dll to this file test.cs
ALL THE BEST
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.
-
I want to add another external dll to this file for example add.dll to this file test.cs
ALL THE BEST
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... "
-
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.
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
-
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
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.
-
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.
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
-
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
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(); } }
-
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
-
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? ;)
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