title: WPF Application Crash After running from C:\Program Files (x86)\ OR by C:\Program Files
body: <p>i have made an application in WPF , which is calling data via REST API by making request &amp; getting Response , After getting Response I am downloading all the Image files &amp; <strong>encrypting</strong> it &amp; saving on my <strong>local drive</strong> &amp; putting path of local encrypted Image in my <strong>Local DB</strong> which is in my application (SQL server Compact 4.0).</p>
  
  <p>All of above process is running in background Thread .</p>
  
  <p>Now the <strong>presentation</strong> layer of application always look up in to <strong>local DB</strong>, if get any Image path the application decrypt it by following way &amp; use it  to display on presentation layer.             </p>
  
  <pre><code>Image img_home = new Image();
  img_home.Width = 1920;
  img_home.Height = 1080;  
  img_home.Source = DecryptFile.LoadBitmapImages(mediaPath); 
  grid_main_Home_page.Children.Add(img_home);
  
  //where grid_main_Home_page is a Grid in application
  
  public static BitmapSource LoadBitmapImages(string ImagePath_to_Save)
  {
      byte[] ImageBytes;
      BitmapSource bs1;
      // if (File.Exists(ImagePath_to_Save))
      //{
          ImageBytes = File.ReadAllBytes(ImagePath_to_Save);
          using (System.IO.MemoryStream Stream = new System.IO.MemoryStream(ImageBytes))
          {
              Bitmap source = new Bitmap(Stream);
              IntPtr ip = source.GetHbitmap();
              bs1 = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, Int32Rect.Empty,
  
              System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
  
              return bs1;
          }
      // }
  }
  </code></pre>
  
  <p>My application working fine when i am running application directly by .exe any where in my machine.</p>
  
  <p>As i am running my application by C:\Program Files (x86)\ OR by C:\Program Files , it is going to crash by showing following error--<img src="https://i.stack.imgur.com/qt9wV.png" alt="enter image description here"></p>
  
  <p>as I am <strong>looking in the directory the Image file is exits</strong> , If i am putting that part of code in <strong>try catch block</strong> but still getting same error .</p>
  
  <p>If I am putting image source like </p>
  
  <pre><code>img_home.Source =new BitmapImage(new Uri(mediaPath,UriKind.Absolute)); 
  </code></pre>
  
  <p>it's working fine , but i don't want it because here i need to decrypt &amp; save the file in local drive .</p>
  
  <p>Please help me , i am struggling on it .</p>
  
  <p>Regards</p>
  
  <p>Anupam mishra</p>