How to get around DnsRecordListFree error in .NET Framework 4.0?

前端 未结 1 682
灰色年华
灰色年华 2021-01-16 13:38

I am doing an MxRecordLookup. I am getting an error when calling the DnsRecordListFree in the .NET Framework 4.0. I am using Windows 7. How do I get around it? Here is t

相关标签:
1条回答
  • 2021-01-16 14:12

    Read Security Changes in the .NET Framework 4 to understand what transparent and critical code is. By default, in .NET 4, any code in an assembly marked with AllowPartiallyTrustedCallersAttribute is transparent, which means it cannot call critical code (code marked with SecurityCriticalAttribute). Only security safe critical (marked with SecuritySafeCriticalAttribute) or critical code can call critical code. And security safe critical can be called by transparent called.

    In short:

    Transparent can call Transparent or Security Safe Critical
    Security Safe Critical can call Security Safe Critical or Critical
    Critical can call Critical

    Enable Code Analysis with the Microsoft Security rules set to see warnings about bad security calls. Note that you can revert back to how security worked in .NET Framework 2.0 (all code is critical) by applying [assembly: SecurityRules(SecurityRuleSet.Level1)] or removing AllowPartiallyTrustedCallersAttribute. See Security-Transparent Code, Level 2 for more information.

    To comply with the new rules, GetMXRecords should become SecuritySafeCritical and the DLL import calls must be marked with SecurityCritical.

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