Problems using FileStream in a seperate AppDomain

D

Dan Dorey

Hey,

I've created a very simple test app to try and fix a problem I'm
having. Basically I'm trying to log to a text file from a class in a
seperate app domain that I've created. When I first create the
AppDomain I'm able to log. However, I have the requirement that I'll
have to tear down the AppDomain and then load it back up again. When I
do this I no longer get any logging.


Note that the first thing I thought of is that the file was somehow not

being release, but I've modified the code below to create with a
different filename each time the AppDomain is loaded with no success.


Any help would be appreciated!


***** Text Logger *****


using System;
using System.IO;
using System.Text;


namespace prairieFyre.IQRealtimeClient
{
public class TestLogger : MarshalByRefObject
{
StreamWriter m_fileWriter;


public TestLogger()
{
FileStream stream = new FileStream("TestLogger.txt",
FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
m_fileWriter = new StreamWriter(stream);


}


public void WriteText()
{
m_fileWriter.WriteLine("THIS IS MY TEST!");
m_fileWriter.Flush();
}
}



}


******* Test App *******

(this loads the AppDomain)
m_realtimeAppDomain = AppDomain.CreateDomain("Realtime AppDomain");
TestLogger testLogger =
(TestLogger)m_realtimeAppDomain.CreateInstanceAndUnwrap("RealtimeClient",

"prairieFyre.IQRealtimeClient.TestLogger");


testLogger.WriteText();
testLogger.WriteText();


(This is how I unload the AppDomain)
AppDomain.Unload(m_realtimeAppDomain);
m_realtimeClient = null;
 
W

Willy Denoyette [MVP]

Please post a 'complete' sample that illustrates the issue, not just a
couple of code snippets.

Willy.

| Hey,
|
| I've created a very simple test app to try and fix a problem I'm
| having. Basically I'm trying to log to a text file from a class in a
| seperate app domain that I've created. When I first create the
| AppDomain I'm able to log. However, I have the requirement that I'll
| have to tear down the AppDomain and then load it back up again. When I
| do this I no longer get any logging.
|
|
| Note that the first thing I thought of is that the file was somehow not
|
| being release, but I've modified the code below to create with a
| different filename each time the AppDomain is loaded with no success.
|
|
| Any help would be appreciated!
|
|
| ***** Text Logger *****
|
|
| using System;
| using System.IO;
| using System.Text;
|
|
| namespace prairieFyre.IQRealtimeClient
| {
| public class TestLogger : MarshalByRefObject
| {
| StreamWriter m_fileWriter;
|
|
| public TestLogger()
| {
| FileStream stream = new FileStream("TestLogger.txt",
| FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
| m_fileWriter = new StreamWriter(stream);
|
|
| }
|
|
| public void WriteText()
| {
| m_fileWriter.WriteLine("THIS IS MY TEST!");
| m_fileWriter.Flush();
| }
| }
|
|
|
| }
|
|
| ******* Test App *******
|
| (this loads the AppDomain)
| m_realtimeAppDomain = AppDomain.CreateDomain("Realtime AppDomain");
| TestLogger testLogger =
| (TestLogger)m_realtimeAppDomain.CreateInstanceAndUnwrap("RealtimeClient",
|
| "prairieFyre.IQRealtimeClient.TestLogger");
|
|
| testLogger.WriteText();
| testLogger.WriteText();
|
|
| (This is how I unload the AppDomain)
| AppDomain.Unload(m_realtimeAppDomain);
| m_realtimeClient = null;
|
 
Top