Problem with Building DLL after the AppDomain is unloaded.

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Problem with Building DLL after the AppDomain is unloaded.

    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\\M yClass.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\\My Clas
    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.
    Raveendra M Guest

  2. Similar Questions and Discussions

    1. Appliation unloaded!!!
      Hi, I'm looking for a way to detect when an user leaves a flex application. I want to be able to make an action when an user closes the browser,...
    2. AppDomain.UnhandledException dose note fired
      Hi All I use following code to register event handler protected void Application_Start(Object sender, EventArgs e) {...
    3. Appdomain unloded under IIS 5.0
      My application, which is a hand-coded HttpModule (not created with Visual Studio.NET) is acting inconsistently on different machines. I have a unit...
    4. It is not allowing build the DLL after unloading the AppDomain
      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...
    5. Is there a way to unload the current appdomain?
      If I have two applications that are side by side they both use the same instance of the aspnet_wp.exe. How can I unload one of these applications...
  3. #2

    Default Re: Problem with Building DLL after the AppDomain is unloaded.

    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..........

    "Raveendra M" <raveendra_m@hotmail.com> schrieb im Newsbeitrag
    news:038301c354cd$8e5aa580$a501280a@phx.gbl...
    > 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\\M yClass.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\\My Clas
    > 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.

    Jerry Guest

  4. #3

    Default Problem with Building DLL after the AppDomain is unloaded.

    Use this for load dll.This code not lock file.

    FileStream fs = File.Open(@"C:\TestDll.dll",FileMode.Open);
    byte[] data = new byte[fs.Length];
    fs.Read(data, 0, data.Length);
    fs.Flush();
    fs.Dispose();
    fs = null;

    Assembly a = Assembly.Load(data);
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139