Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

AppDomainAssemblyTypeScanner locks DLL files #2123

@nourselim0

Description

@nourselim0

I'm using Nancy to make a small service that gets called from a main ASP.NET MVC application, during testing I have the self-host Nancy EXE and the main web app's DLLs in the same folder, and I noticed that I can't rebuild the web app while the EXE is still running because the DLL files are locked (in-use).
After digging around for a long time I found the problem to be in AppDomainAssemblyTypeScanner.LoadAssembliesWithNancyReferences where it calls Assembly.ReflectionOnlyLoadFrom which effectively locks the DLL files.
I've looked around on how to solve this, and discovered that you can't unload an assembly and you have to unload the whole AppDomain instead, I tried to create a new AppDomain just for the sake of the assembly inspection and called AppDomain.Load instead of Assembly.ReflectionOnlyLoadFrom then unloaded this temp AppDomain but that didn't work, it seems that AppDomain.Load also loads the assembly into the current AppDomain.
So after more searching around I found this: http://www.codeproject.com/Articles/453778/Loading-Assemblies-from-Anywhere-into-a-New-AppDom
It seems that in order to do this correctly the inspection code has to run completely under the new AppDomain and the results marshalled back to the main AppDomain.

Now I'm almost completely new to the concepts of AppDomains and Marshalling, I know the concepts but never implemented anything that touches these areas. I could try to implement this technique into ADATS but I feel I don't have the skills to do it correctly, I'm also worried that it might cause performance issues.
So I'm asking for your opinions about this. Did anybody here think of this before? If yes, then why didn't you implement this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions