CallbackBehavior ignored from a base class
- Dominant language
- C#
- Stars
- 1.8k
- Forks
- 576
- Avg merge
- 6d 9h
- Merged PRs (30d)
- 2
Description
**Describe the bug**
If you define CallbackBehavior for a callback for a DuplexClient, and then derive another class from that, that CallbackBehavior is not captured by the ServiceEndpoint for the DuplexClientBase. In the system ServiceModel for .Net Framework, this is not a problem. CallbackBehavior is captured in each base class.
**To Reproduce**
Steps to reproduce the behavior:
1. Define a Callback class, derived from a callback interface.
2. Specify a CallbackBehavior attribute, such as [CallbackBehavior(ConcurrencyMode=ConcurrencyMode.Multiple)]
3. Define a Callback class derived from the first, with no CallbackBehavior attribute.
4. Create a DuplexClient using the derived Callback class as the callback.
5. The service endpoint that is generated will not have the CallbackBehavior from the base callback class. It will have a default one with ConcurrencyMode.Single set.
**Expected behavior**
CallbackBehavior attributes should be settable anywhere in the class tree.
**Additional context**
I have found the cause of this problem. It is in the TypeLoader.AddBehaviorsFromImplementationType function. The first foreach loop calls ServiceReflector.GetCustomAttributes, with "false" as the 3rd parameter. That parameter indicates whether it should inherit attributes. It should. Changing that parameter to "true" fixes the problem.
I am not submitting a pull request with this fix, in part, because there are many places where GetCustomAttributes is passed false, and I expect that some other places also should be passing true. I have not looked at all of those paths, and I do not have the experience in WCF to know which ones should and which ones shouldn't inherit. I just know that in this case, I had code that worked in .Net Framework and that broke in .Net Core, and this was the problem.
Contributor guide
Assessment
This issue has not been assessed yet.