Bug 37035 - Creating service host with singleton fails
Summary: Creating service host with singleton fails
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies ()
Version: 4.2.0 (C6)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Aleksey Kliger
Depends on:
Reported: 2015-12-15 18:27 UTC by greg
Modified: 2015-12-22 16:48 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description greg 2015-12-15 18:27:39 UTC
The following code fails on Linux with exception:" When creating a Service host with a service instance, use InstanceContextMode.Single in the ServiceBehaviorAttribute." and works on windows:

 mono --version
Mono JIT compiler version 4.2.1 (Stable Thu Nov 12 09:52:44 UTC 2015)

using System;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;

namespace foo

    static class Program
        static void Main(string[] args)
            var uri = $"http://localhost:8732/Design_Time_Addresses/AudioVideo/";
            WebServiceHost host = new WebServiceHost(new AudioVideo(), new Uri(uri));
                var ServiceBehavAttr = (ServiceBehaviorAttribute)Attribute.GetCustomAttribute(typeof(AudioVideo), typeof(ServiceBehaviorAttribute));
                if (ServiceBehavAttr != null)
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IAudioVideo), new WebHttpBinding(), "");
                host.Open();  // fails on linux with ... use InstanceContextMode.Single in the ServiceBehaviorAttribute
                using (var cf = new ChannelFactory<IAudioVideo>(new WebHttpBinding(), uri))
                    cf.Endpoint.Behaviors.Add(new WebHttpBehavior());

                    var channel = cf.CreateChannel();

            catch (Exception ex)
        public interface IAudioVideo
            [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped)]
            void Start();
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
        public abstract class Component

        public class AudioVideo : Component, IAudioVideo
            public void Start() { }
Comment 1 Aleksey Kliger 2015-12-21 19:38:21 UTC
Mono ServiceHost implementation was using GetCustomAttributes(..., false) to get the ServiceBehaviorAttribute from the service type.

As a workaround, you can put the attribute on the AudioVideo class directly, not on its parent class.
Comment 2 Aleksey Kliger 2015-12-22 16:48:16 UTC
Fixed in master commit 5c7b6ea2200218f57e4feb657dc2926ca30a31e9