I'm building a windows application where I can call coded UI project (project named RecordAndPlayback) by clicking on a button. My aim is to call the test methods in the coded UI project and then be able to modify the test then call it back from my win app without closing it using the same button.
I managed to call the test method, but I have a problem in modifying the test method after that. Whenever I build my coded UI project, I get an error
ERROR CSC(0,0): Unexpected error creating debug information file '...\obj\Debug\RecordAndPlayback.PDB' -- '...\obj\Debug\RecordAndPlayback.pdb: The process cannot access the file because it is being used by another process.
I used AppDomain
to load the dll in it and then unload the AppDomain
in hope that the dll will be released. I managed to do that, but then I got the above error in the .pdb file. I found another solution which I found much simpler but still got the above problem.
Here is my code sample so far:
string dllPath = @"...\bin\Debug\RecordAndPlayback.dll";
byte[] fileContent;
using (FileStream dll = File.OpenRead(dllPath))
{
fileContent = new byte[dll.Length];
dll.Read(fileContent, 0, (int)dll.Length);
}
var DLL = Assembly.Load(fileContent);
Playback.Initialize();
foreach (Type type in DLL.GetExportedTypes())
{
if (type.Name == "CodedUITest1")
{
var c = Activator.CreateInstance(type);
try
{
type.InvokeMember("CodedUITestMethod1", BindingFlags.InvokeMethod, null, c, new object[] { });
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
break;
}
}
Playback.Cleanup();
I tried using the AppDomain
but it didn't work. Actually the above code is the best I got so far, I'm sure that the .dll file is released as I'm able to delete it. Also, the .pdb file in the bin folder is released (also was able to delete it). My problem is the .pdb file in the obj folder. The only way is that I must close my windows application project so I can build my coded UI project.
How can I fix this without closing my win app?