Thanks for your fast answer.
I am calling a native dll using the P/Invoke signature and I am the only one who is using the native dll so according to your answer it sounds that FreeLibrary is an accepted way to unload the dll. It was working for me fine but I wasn't sure it is the right
way to unload it.
Anyway the solution above was done since I failed to do it using ijw. I will describe what I have done and tell me if something is wrong:
1. I have created a managed dll which defines the interface that was implemented in ijw dll.
2. I have created the ijw dll which implement the interface.
3. In a wcf service I added a refference to the managed dll that contains the interface.
4. Inside one of the wcf service methods I have created new appdoamin and created the managed type from the ijw dll by reference in the wcf service process (w3wp.exe). The reference pointer is from type of the interface so no need for the default appdomain
to load the ijw dll.
5. When I looked at modules I can see the ijw dll appears in both the default appdomain and the new appdomain I have created.
6. after unloading the new appdomain the dll still appears in the w3wp process at the default appdomain.
Do you have an idea what cause this behaviour? is it the fact that it runs under IIS causing the CLR to behave differently then in a console process?