0

I have a WinForm application and on startup I extract a *.dll from the embedded resources (Properties.Resources).

My application needs this later (Ionic.Zip-library). But when the application closes, how can I then delete this *.dll? Because now I get an error that the access is denied

Do I first need to un-reference it? Or is there even another way to completely let the *.dll inside my *.exe? Because at the end it should only be one *.exe.

Microsoft DN
  • 9,706
  • 10
  • 51
  • 71
Postback
  • 619
  • 2
  • 9
  • 27

1 Answers1

2

You cannot unload a loaded dll from a running AppDomain.

You can however start a new AppDomain, load the dll there, and afterwards, when you are closing the application, unload the AppDomain. After you have unloaded the AppDomain, the extracted dll is no longer referenced by the the running process, and can be deleted.

This however has a consequence - you can only use you extracted dll inside the created AppDomain. Some googling might give you more information.

Maarten
  • 22,527
  • 3
  • 47
  • 68
  • I've googled around a bit. But faced another problem, I create a new AppDomain now, and there I'll load the *.dll, but i have to remove it in VS from references, right? but then the compiler complains about he doesnt know `Ionic.Zip`. How can I tell him that I'll load the dll later? – Postback Jul 15 '13 at 07:03
  • 1
    You'll have to make a separate assembly which IS referencing the Ionic.zip dll. You'll also have to create a class in this assembly which starts the code which uses the Ionic.zip dll. Check this answer: http://stackoverflow.com/a/6578195/261050 – Maarten Jul 15 '13 at 07:24