c# - AppDomainSetup.PrivateBinPath vs Environment.SetEnvironmentVariable -


i need app know unmanaged dlls. using setenvironmentvariable , working great. know there property appdomainsetup.privatebinpath. practical difference between them?

currently doing below:

var dlldirectory = @"c:\some\path"; environment.setenvironmentvariable("path", environment.getenvironmentvariable("path") + ";" + dlldirectory) 

edit: noticed environment.setenvironmentvariable not change path variable, seams affect app have called it.

privatebinpath clr assemblies.

which not windows dlls, doesn't know clr configuration. uses regular windows search rules, behaves this:

  1. same directory exe stored
  2. the directory specified in set/adddlldirectory() call, if any
  3. the windows system directory (normally c:\windows\system32)
  4. the windows install directory (normally c:\windows)
  5. the current default directory (environment.currentdirectory)
  6. the directories listed in path environment variable.

several quirks this, has been tinkered lot. particularly bullet 5 security problem , can abused program load rogue dll. close enough can expect in wild.

setting path environment variable in code okayish, not reliable. being on bottom of list of course issue, might wrong dll loaded. , path environment variable troublesome, can corrupted on machine , may long allow append directory it. hard diagnose problems.

you should always, always, always favor bullet 1. copy native dlls same directory exe. works, reliable, never surprise, no special config needed. nobody cares directory bit full, not customer, not file system, not operating system.

if have favor bullet 2, pinvoke setdlldirectory(). not reliable, you'll have trouble if 1 of dlls load using too. find out. using adddlldiretory() better isn't supported on enough windows versions yet relied upon.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -