Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6117415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:19:05+00:00 2026-05-23T15:19:05+00:00

We are using IoC and have our logging exposed with it. We are using

  • 0

We are using IoC and have our logging exposed with it. We are using Common.Logging and I have written a matching delegate for Common.Logging.FormatMessageHandler but I do not know how to convert from our version of that delegate to the one that the Common.Logging api is expecting.

This question appears to be similar but I do not understand how to convert from my implemented type to the known type that I want to call.
Dynamically casting one type of delegate to another

Here is my delegate signature:

public delegate string FormatMessageHandler(string format, params object[] args)

Here is Common.Logging’s:

public delegate string FormatMessageHandler(string format, params object[] args)

Same name (not that is matters) and same number of parameters. Both are known at compile time so it should be something obvious but I am not seeing it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:19:05+00:00Added an answer on May 23, 2026 at 3:19 pm

    Why are you not using Common.Logging’s delegate in the first place if it is exactly the same?

    However, a solution to your problem is to either use the dynamic cast explained in the article linked in the question you mentioned, or you do it like this:

    YourNamespace.FormatMessageHandler yourHandler = ...;
    Common.Logging.FormatMessageHandler handler = (f, a) => yourHandler(f, a);
    

    UPDATE:
    According to your comment, you want something like that:

    public void Error(Action<Your.FormatMessageHandler> formatMessageCallback)
    {
        _logger.Error(h => formatMessageCallback((f, a) => h(f, a)));
    }
    

    This will create a new action with one parameter h of type Common.Logging.FormatMessageHandler which calls the supplied action formatMessageCallback with a new delegate of Your.FormatMessageHandler that accepts two parameters f and a. This new delegate in turn calls h with the two supplied parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using IoC for a little while now and I am curious
I'm working on my 1st project using MS Unity IoC framework. If I have
I'm trying to enable SqlCacheDependency through my StructureMap IoC, I'm using LinqToSql I have
I'm trying to add generic service support to our IoC container, and I have
I having some problems implementing IOC using windsor. I have several different implementations of
When using an IoC container, is it considered good design to inject other classes
Can someone explain to me the advantages of using an IOC container over simply
I'd like to get a feel for what people are using for IoC containers.
I am using windsor castle as my IoC container, and has run in to
It's rare that I hear someone using Inversion of Control (Ioc) principle with .Net.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.