Reflection.Assembly not releasing Assembly

Denaes

Senior Contributor
Joined
Jun 10, 2003
Messages
956
Code:
error MSB3021: Unable to copy file "obj\Debug\Common.DataAccess.dll" to "bin\Debug\Common.DataAccess.dll". The process cannot access the file 'bin\Debug\Common.DataAccess.dll' because it is being used by another process.
Done building project "Common.DataAccess.vbproj" -- FAILED.

I call a Macro that loads the "bin\Debug\Common.DataAccess.dll" file into an Assembly instance, then I use getTypes() to run through all the types and I copy some names off into a collection for use in the Macro.

At this point, I set the assembly instance = to nothing. There isn't any Dispose or ReleaseAssembly.

But when I attempt to rebuild the "Common.DataAccess.dll", I get the error that it's in use.

Looking at various pages, MS's example doesn't even set the assembly to nothing and most of the examples only set the instance to nothing.

None of it's methods/properties seem like they would help. So how can I force this to release it's hold on the file?

Here is the code I'm roughly using:

Visual Basic:
        Dim assData As Reflection.Assembly
        assData = Assembly.LoadFrom(Path)

        For Each typeData As Type In assData.GetTypes
            If typeData.FullName Like "TableAdapter" Then
                ' Code to copy text from the type
            End If
        Next

        assData = Nothing

I load it, I get it's types and then set it to nothing.
 
Last edited:
Marble_Eater suggested using the AppDomain as well in another thread.

But... there is always a but.

I'm doing this at design time, not runtime. An Assembly can only be loaded into one AppDomain at a time and because the Assembly I'm loading is loaded into the projects (or solutions, I'm not sure) AppDomain, I can't load it into a new AppDomain.
 
Back
Top