I just get an error each time I run this code:
AppDomain newDomain = AppDomain.CreateDomain("newDomain");
AssemblyName assemblyName = AssemblyName.GetAssemblyName(path);
Command cmd = (Command)newDomain.CreateInstanceAndUnwrap(assemblyName.FullName, typename);
cmd.Execute();
Where path
is the path of the Dll and typename
is "NWT_Projekt.TestClass"
My command class:
using System;
namespace NWT_Projekt
{
public interface Command
{
void Execute();
}
}
and this is the source code of the DLL
using System;
using System.Collections;
using System.Xml;
using System.IO;
using System.Windows.Forms;
namespace NWT_Projekt
{
public class TestClass : NWT_Projekt.Command
{
public MainForm f;
public TestClass()
{
f = Form.ActiveForm as MainForm;
}
public void Execute()
{
//do something
}
}
}
ERROR (google translator :D)
An exception of type "System.Runtime.Serialization.SerializationException 'occurred in NWT PRojekt.exe.
Additional information: The type "NWT_Projekt.TestClass' in Assembly 'scripts, Version = 0.0.0.0, Culture = neutral, PublicKeyToken = null' is not marked as serializable.
EDIT2:
With the [Serializable] it works now, but after I run the code one time and then I want to create a second dll it gives me an IO error, because the file is in use! How can I fix this?