Problem with Building DLL after the AppDomain is unloaded.

  • Thread starter Thread starter Raveendra M
  • Start date Start date
R

Raveendra M

Hi!
I am working with ASP.NET application. In my page I am
creating one Application Domain and in that domain I am
calling my DLL. Using the methods of the dll. And
unloading the Application Domain. Till this point it is
working fine.
My problem is, while web page is open, than I am modifying
the dll, and rebuilding. Then it is giving error:
"The file 'MyClass.dll' cannot be copied to the run
directory. The process cannot access the file because it
is being used by another process."

How do I over come this problem?

My ASPX page code is :
==========================================================
private void Page_Load(object sender, System.EventArgs e)
{
InitMethod();
}
private void InitMethod()
{
AppDomainSetup info = new
AppDomainSetup();
info.ApplicationBase = "file:///"
+ System.Environment.CurrentDirectory;
// Create an application domain
with null evidence
AppDomain dom =
AppDomain.CreateDomain("RemoteDomain", null, info);
// Tell the AppDomain to execute
the assembly
System.Reflection.Assembly a =
System.Reflection.Assembly.LoadFrom
("D:\\Raveendra\\APPDomain\\MyClass\\bin\\Debug\\MyClass.dl
l");
object o = a.CreateInstance
("MyClass.Class1",
false,

System.Reflection.BindingFlags.Public |

System.Reflection.BindingFlags.Instance |

System.Reflection.BindingFlags.InvokeMethod,
null,
null,

null,
null);

System.Type t = o.GetType ();

Object result = t.InvokeMember
( "FindSum",

System.Reflection.BindingFlags.Public |

System.Reflection.BindingFlags.Instance |

System.Reflection.BindingFlags.InvokeMethod ,
null, o, new object [] {});

Response.Write (result);
//Call a method with arguments
object [] args = new object []
{100, 184};

Object result1 = t.InvokeMember
( "FindSum1",

System.Reflection.BindingFlags.Public |

System.Reflection.BindingFlags.Instance |

System.Reflection.BindingFlags.InvokeMethod ,
null, o, args);
TextBox1.Text = result1.ToString
() ;
AppDomain.Unload(dom);
}

==========================================================
In brief my problem is :
when the try to build the Dll in the
path "D:\\Raveendra\\APPDomain\\MyClass\\bin\\Debug\\MyClas
s.dll", while ASP.NET page is running, it is not allowing
me. How to over come this problem, with out stoping the
IIS?

Thanks for your help.
 
Ho

I have the same Problem (it not occurs every compile/start.... very
strange...)

As Workaround I restart the IIS with a Batch File:

net stop W3SVC
net stop SMTPSVC
net stop MSFTPSVC
net stop IISADMIN
net start IISADMIN
net start W3SVC
net start SMTPSVC
net start MSFTPSVC
pause

I hope someone has a better Idea..........
 
Back
Top