question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[AutoResolve] not working as expected

See original GitHub issue

I’m having a hard time reconciling various sources to create a custom Azure Function App binding.

I find examples that bind an attribute and its values to an input argument type using BindToInput(). I also find examples that use an IBindingProvider-implementation using Bind().

However, I cannot find samples that use both an IBindingProvider-implementation while still making use of an attribute. Specifically, I need my custom binding to access values specified at the attribute level.

Repro steps

I have uploaded a sample custom binding with:

  • A custom attribute with an [AutoResolve] decorated property.
[Binding]
[AttributeUsage(AttributeTargets.Parameter)]
public class AuthorizeAttribute : Attribute
{
    /// <summary>
    /// Initialize a new instance of the <see cref="AuthorizeAttribute" /> class.
    /// </summary>
    /// <param name="applications"></param>
    public AuthorizeAttribute(string applications)
    {
        Applications = applications;
    }

    /// <summary>
    /// The comma-separated list of allowed application identifiers (client-ids).
    /// May contain binding parameters.
    /// </summary>
    [AutoResolve]
    public string Applications { get; private set; }
}
  • My config provider uses the following code to try and retrieve the attribute:
/// <summary>
/// Creates the <see cref="ClaimsPrincipalBinding" /> class.
/// </summary>
/// <param name="context"></param>
public Task<IBinding> TryCreateAsync(BindingProviderContext context)
{
    var parameter = context.Parameter;
    var attribute = parameter.GetCustomAttribute<AuthorizeAttribute>(inherit: false);

    IBinding binding = new ClaimsPrincipalBinding(attribute, logger_);
    return Task.FromResult(binding);
}

When using this custom binding, the attribute variable is initialized with the value specified from the function’s code. For instance, instead of resolving the configuration value from app settings, the binding receives values such as %MyConfiguration% including the percent-characters.

Expected behavior

I would expect the attribute variable to receive the value referred to by the configuration parameter from app settings.

Actual behavior

The attribute variable is initialized with the value specified in the source code verbatim, including %-characters.

Summary

Is there any reliable sample that illustrates this problem? How can I make sure [AutoResolve] works and resolve configuration parameters from app settings.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mathewccommented, Oct 11, 2022

When implementing the binding yourself by providing your own IBindingProvider, AutoResolve won’t work. Instead, you must use INameResolver to manually resolve the attribute value. An example can be found here. So you’d update your config provider to take the INameResolver from DI and flow it down into your binding provider (example here), and call ResolveInWholeString yourself.

AutoResolve works only if you’re using the BindToInput method, as you’ve found. That method auto creates the binding for you rather than you implementing an IBindingProvider, and that auto binding passes the attribute through an AttributeCloner which is the component that honors AutoResolve.

0reactions
springcompcommented, Oct 12, 2022

@mathewc thanks a lot.

That is awesome and informative feedback and looks like exactly what I was looking for. Will let you know if I need more help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto resolve is broken : r/totalwar
Not only are Beastmen bad at AR, but Ungors are broken in Auto Resolve and will actually lower your AR score if you...
Read more >
The Auto resolve as to be fixed
Total War: WARHAMMER III - Known Issues: Autoresolve values seems overly favourable towards the player in Immortal Empires.
Read more >
Outlook Autoresolve not working
I click new email. Type in john and hit enter and or tab. Nothing happens and the "to" field simply says john. I...
Read more >
autosolve combat causes a big problem :: SpellForce
The problem is that apparently one of the things the auto resolve does take into account is resistances and damage types, and it...
Read more >
Is auto resolve that good or am I just that bad? :: Total War
The purpose of the Autoresolve function is to trivialize battles that you should not really need concern yourself with wasting time actually fighting....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found