SecurityException: ECall methods must be packaged into a system module

前端 未结 2 1132
盖世英雄少女心
盖世英雄少女心 2020-12-17 07:55

I have a (C#) function similar to the following.

private static bool SpecialCase = false;

public void Foo()
{
    if (SpecialCase)
    {
        InternalMet         


        
相关标签:
2条回答
  • 2020-12-17 08:25

    Add attribute [ComImport] to your class declaration

    0 讨论(0)
  • 2020-12-17 08:26

    You may want to check the compiler directives as a possible option. Unlike using a run-time "if", this will determine whether the call is included in the compiled code at all, rather than always compiling it into the code and trying to determine whether to call it at run-time (which is too late, based on your analysis).

    Your use-case seems like a testing/validation scenario, which means that you don't need it compiled into the code except when the internal call will actually be made.

    Note that if your use-case involves a non-.NET runtime, you should provide more information since that could drastically change the correct answer.

    0 讨论(0)
提交回复
热议问题