I am developing a very simple Generic Host solution that will allow us to host assemblies as Windows services (ala NServiceBus). I come across the following exception (like the comments mentioned in the Dru blog post ). I need this to work, so I can host services in different AppDomains.
"Type 'MyProject.WindowsServices.GenericHost.Program + <> c__DisplayClass5' in Assembly 'MyProject.WindowsServices.GenericHost, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null' is not marked as serializable."
I use the Topshelf 1.0 RC binaries available from the download link on the topshelf homepage (topshelf-project.com). I tried the latest build (07/29/2010), and builds can be downloaded from google-code and github! I can’t get any of them to work for me!
This works in the NServiceBus library with the old version of Topshelf (dll version version 0.8.0.96). With some minor code changes to what I have below (use CreateServiceLocator instead of HowToBuildService), it works for me with these old binaries, but I would prefer to use the latest code to take advantage of any planned fixes or improvements.
Here is my code.
static void Main(string[] args)
{
ArgumentParser arguments = new ArgumentParser(args);
string configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
arguments.ServiceType.Assembly.ManifestModule.Name + ".config");
RunConfiguration cfg = RunnerConfigurator.New(x =>
{
x.SetServiceName(arguments.ServiceName);
x.SetDisplayName(arguments.DisplayName);
x.SetDescription(arguments.Description);
if (string.IsNullOrEmpty(arguments.UserName))
{
x.RunAsLocalSystem();
}
else
{
x.RunAs(arguments.UserName, arguments.Password);
}
x.ConfigureServiceInIsolation<GenericHost>(c =>
{
c.ConfigurationFile(configFile);
c.Named(arguments.ServiceType.AssemblyQualifiedName);
c.HowToBuildService(name => new GenericHost(arguments.ServiceType));
c.WhenStarted(tc => tc.Start());
c.WhenStopped(tc => tc.Stop());
});
});
Runner.Host(cfg, args);
}
, GenericHost , . ServiceType MarshalByRefObject, Serializable, , . , , , , , # lambda, .
- ConfigureServiceInIsolation()? , - , ? , , . .