Patching problem

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 3
Reputation: Sergei82 is an unknown quantity at this point 
Solved Threads: 0
Sergei82 Sergei82 is offline Offline
Newbie Poster

Patching problem

 
0
  #1
Oct 1st, 2008
The problem: I have an executable and mylib.dll (C# class library) in the same directory. I have a subdirectory "Patch" in that directory containing another version of that mylib.dll. I need to make a sample application somehow that loads the first dll, than frees it (like LoadLibrary and FreeLibrary in Windows API, but here I use Domain.Load, Domain.Unload), and then loads another version of that dll from "Patch" folder.
Problems:
1) when I try to load the library from "Patch" directory, the library from the application directory is loaded (even if I add some other paths to domain),
2) if I rename "Patch\mylib.dll" to "Patch\mylib1.dll" and try to load the second, renamed one, it is anyway resolved to its original name and again - assembly from mylib.dll in application directory is loaded,
3) if I unload (free) mylib.dll, delete it from my computer, move "Patch\mylib.dll" to "mylib.dll", load it....... I anyway get the original dll that I deleted... it seems like there is hash,
4) changing "patched" dll version doesn't help - I anyway get the original dll if I loaded it once.
Help me! I'm a novice in these things. How could work with dynamic labraries that was so simple in Windows API become so terribly complicated here, in .NET???
What do I do wrong? How can I free the library and load the new, changed one, but with the same name?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Patching problem

 
0
  #2
Oct 1st, 2008
That sounds odd. Normally if its a newer version the .net framework will pick up the fact the versions changed and the cached version is updated.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3
Reputation: Sergei82 is an unknown quantity at this point 
Solved Threads: 0
Sergei82 Sergei82 is offline Offline
Newbie Poster

Re: Patching problem

 
0
  #3
Oct 1st, 2008
Simple code... maybe, something wrong here...
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Reflection;
  6. using System.IO;
  7.  
  8. namespace PatchedApp
  9. {
  10. class Program
  11. {
  12. public static void LoadInvoke(string path)
  13. {
  14. AppDomain sandbox = AppDomain.CreateDomain("Sandbox");
  15. try
  16. {
  17. AssemblyName an = AssemblyName.GetAssemblyName(path);
  18. Assembly a = sandbox.Load(an);
  19. Type[] mytypes = a.GetTypes();
  20. BindingFlags flags = (BindingFlags.NonPublic | BindingFlags.Public |
  21. BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
  22.  
  23. Console.WriteLine(an.Version.ToString());
  24.  
  25. foreach (Type t in mytypes)
  26. {
  27. MethodInfo[] mi = t.GetMethods(flags);
  28. Object obj = Activator.CreateInstance(t);
  29.  
  30. foreach (MethodInfo m in mi)
  31. {
  32. m.Invoke(obj, null);
  33. }
  34. }
  35. }
  36. catch (Exception ex)
  37. {
  38. Console.WriteLine(ex.ToString());
  39. }
  40. finally
  41. {
  42. AppDomain.Unload(sandbox);
  43. }
  44. }
  45.  
  46. public static void Main(string[] args)
  47. {
  48. string file = Directory.GetCurrentDirectory() + "\\PatchedLib.dll";
  49. string patch = Directory.GetCurrentDirectory() + "\\PatchedLib1.dll";
  50. string temp = "C:\\_PatchedLib.dll";
  51.  
  52. LoadInvoke(file);
  53.  
  54. File.Move(file, temp);
  55. File.Copy(patch, file);
  56. LoadInvoke(file);
  57.  
  58. File.Delete(file);
  59. File.Move(temp, file);
  60.  
  61. Console.ReadKey();
  62. }
  63. }
  64. }
Last edited by cscgal; Oct 2nd, 2008 at 10:57 am. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 3
Reputation: Sergei82 is an unknown quantity at this point 
Solved Threads: 0
Sergei82 Sergei82 is offline Offline
Newbie Poster

Re: Patching problem

 
0
  #4
Oct 5th, 2008
Well, anyway I found the solution to my problem at last:
http://adrianvintu.com/blogengine/po...e-plugins.aspx
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC