Skip to content

Unable to specify interface type to GetCustomAttributes #7190

Closed
@mconnew

Description

@mconnew

On the full framework, WCF looks for any attributes declared on a type where the attribute type derives from IServiceBehavior. This works on the full framework, but on .Net Core an ArgumentException is thrown with the message "Type passed in must be derived from System.Attribute or System.Attribute itself." Here is a simple repro which runs to completion on the full framework but throws on .Net Core.

using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Description;

    class Program
    {
        static void Main(string[] args)
        {
            var ti = typeof(MyService).GetTypeInfo();
            var attrs = ti.GetCustomAttributes(typeof(IServiceBehavior), false);
        }

        [ServiceContract]
        public interface IMyService
        {
            [OperationContract]
            string Hello(string hello);
        }

        public class MyService : IMyService
        {
            public string Hello(string hello) { return hello; }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions