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

  • Home
  • SEARCH
  • 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 8993085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:06:51+00:00 2026-06-15T23:06:51+00:00

In our product, we have things called services which are the basic means of

  • 0

In our product, we have things called “services” which are the basic means of communication between different parts of the product (and especially between languages—an in-house language, C, Python and .NET).

At present, code is like this (Services.Execute utilising params object[] args):

myString = (string)Services.Execute("service_name", arg1, arg2, ...);

I’d rather like to be able to write code like this and get the benefits of type checking and less verbose code:

myString = ServiceName(arg1, arg2, ...);

This can be achieved with a simple function,

public static string ServiceName(int arg1, Entity arg2, ...)
{
    return (string)Services.Execute("service_name", arg1, arg2, ...);
}

But this is rather verbose, and not quite so easy to manage when doing it for scores of services, as I intend to be doing.

Seeing how extern and the DllImportAttribute work, I hope it should be possible to hook this up by some means like this:

[ServiceImport("service_name")]
public static extern string ServiceName(int arg1, Entity arg2, ...);

But I don’t know how to achieve this at all and can’t seem to find any documentation for it (extern seems to be a fairly vaguely defined matter). The closest I’ve found is a somewhat related question, How to provide custom implementation for extern methods in .NET? which didn’t really answer my question and is somewhat different, anyway. The C# Language Specification (especially, in version 4.0, section 10.6.7, External methods) doesn’t help.

So, I want to provide a custom implementation of external methods; can this be achieved? And if so, how?

  • 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-06-15T23:06:52+00:00Added an answer on June 15, 2026 at 11:06 pm

    The C# extern keyword does very little, it just tells the compiler that the method declaration won’t have a body. The compiler does a minimum check, it insists that you provide an attribute as well, anything goes. So this sample code will compile just fine:

       class Program {
            static void Main(string[] args) {
                foo();
            }
    
            class FooBar : Attribute { }
    
            [FooBar]
            static extern void foo();
        }
    

    But of course it will not run, the jitter throws its hands up at the declaration. Which is what is required to actually run this code, it is the jitter’s job to generate proper executable code for this. What is required is that the jitter recognizes the attribute.

    You can see this done in the source code for the jitter in the SSCLI20 distribution, clr/src/md/compiler/custattr.cpp source code file, RegMeta::_HandleKnownCustomAttribute() function. That’s code that’s accurate for .NET 2.0, I’m not aware of additions to it that affect method calling. You’ll see it handling the following attributes that relate to code generation for method calls, the kind that will use the extern keyword:

    • [DllImport], you no doubt know it

    • [MethodImpl(MethodImplOptions.InternalCall)], an attribute that’s used on methods that are implemented in the CLR instead of the framework. They are written in C++, the CLR has an internal table that links to the C++ function. A canonical example is the Math.Pow() method, I described the implementation details in this answer. The table is not otherwise extensible, it is hard-baked in the CLR source code

    • [ComImport], an attribute that marks an interface as implemented elsewhere, invariably in a COM server. You rarely program this attribute directly, you’d use the interop library that’s generated by Tlbimp.exe instead. This attribute also requires the [Guid] attribute to give the required guid of the interface. This is otherwise similar to the [DllImport] attribute, it generates a pinvoke kind of call to unmanaged code but using COM calling conventions. This can of course only work properly if you actually have the required COM server on your machine, it is otherwise infinitely extensible.

    A bunch more attributes are recognized in this function but they don’t otherwise relate to calling code that’s defined elsewhere.

    So unless you write your own jitter, using extern isn’t a viable way to get what you want. You could consider the Mono project if you want to pursue this anyway.

    Common extensibility solutions that are pure managed are the largely forgotten System.AddIn namespace, the very popular MEF framework and AOP solutions like Postsharp.

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

Sidebar

Related Questions

In our system we have an entity Product , which might have various custom
i have developed our company site where we show one product detail means one
We have to create a special interim alpha release for our product which should
With our product we have a simple backup tool for the sql server database.
I'm using nant to build our product and have written a custom task to
In our product, we have frames that are basically three inheritance levels down from
I have a COM inproc DLL that we are using in our product. Now
We have an issue where on a single instance of our product we receive
So Product Management have decreed that our software should have version numbers with 3
Our current product is based on Eclipse RCP. We are starting to have problems

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.