1

I am working on assembly project and external program is executed through the assembly program. System.Environment.CurrentDirectory assembly and Application.ExecutablePath paths are different due to external application. System.Environment.CurrentDirectory is Assembly path. Application.ExecutablePath External application path. While deserialization it throw expcetion

assembly not found

because "Application.ExecutablePath " not having my dlls . So i want to change use System.Environment.CurrentDirectory path for deserialization.

M. Adeel Khalid
  • 1,786
  • 2
  • 21
  • 24
Dhiraj Lotake
  • 29
  • 1
  • 6
  • 1
    I think you should do it like this http://stackoverflow.com/questions/19398748/adding-references-dynamically-in-net – Tomas Smagurauskas Feb 20 '17 at 06:39
  • While deserilzation it throw exception assembly not found because external application "revit.exe" folder not contain my dlls.but when i am copy my dlls to that folder the works fine. – Dhiraj Lotake Feb 20 '17 at 07:08
  • According to that example, you could just hard code paths to your assembly and they would load withouth them being in the same folder as your exe – Tomas Smagurauskas Feb 20 '17 at 07:14
  • It's possibly a security exception. Is there an inner exception? A full exception with code will get you an answer, you've not supplied enough information. – Mick Feb 20 '17 at 07:35

1 Answers1

3

I recommend setting up an AssemblyResolve event on the current domain. That way you can explicitly determine where your DLLs are and load them if they're not found automatically.

Jeremy Tammik wrote about it here: http://thebuildingcoder.typepad.com/blog/2014/05/rvtva3c-assembly-resolver.html

The only thing to be careful of is that you should make sure the event is looking specifically for your DLLs (not any DLLs) - and that if it's not appropriate for you to load a DLL you return null (I occasionally run into scenarios where other people's addins don't implement this nicely, and it messes up my addin doing it).

Matt
  • 1,043
  • 5
  • 8