[C#] foutmelding tijden uitvoeren functie GetVersionEx

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Sinds ik mijn project heb omgezet naar .NET 4.0 krijg ik onderstaande beveiligings melding wanneer ik de applicatie run:

Attempt by security transparent method 'Micpoint.Windows.Common.OperatingSystemVersion.UseOSVersionInfoEx(OSVERSIONINFO)' to call native code through method 'Micpoint.Windows.Common.OperatingSystemVersion+NativeMethods.GetVersionEx(OSVERSIONINFO)' failed. Methods must be security critical or security safe-critical to call native code.


C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private class NativeMethods
        {
            private NativeMethods() {}

            [ DllImport( "kernel32.dll", SetLastError = true, CharSet = CharSet.Auto ) ]            
            public static extern bool GetVersionEx
                (
                    [ In, Out ] OSVERSIONINFO osVersionInfo
                );

            [ DllImport( "kernel32.dll", SetLastError = true, CharSet = CharSet.Auto ) ]
            public static extern bool GetVersionEx
                (
                    [ In, Out ] OSVERSIONINFOEX osVersionInfoEx
                );

        }


Ik weet dat er in .NET Framework 4.0 een groot aantal dingen zijn gewijzigd omtrent beveiliging van de uitvoer van code, maar ik kom er maar niet uit.

Om het probleem te 'omzeilen' heb ik het onderstaande geprobeerd, dit heeft echter geen effect:

code:
1
2
3
4
5
<configuration>
  <runtime>
    <NetFx40_LegacySecurityPolicy enabled="true" />
  </runtime>
</configuration>


Heeft iemand een idee hoe dit netjes op te lossen is, zodat de functie toch gebruikt kan worden?

Alvast bedankt voor jullie hulp!

Acties:
  • 0 Henk 'm!

  • alex3305
  • Registratie: Januari 2004
  • Laatst online: 15-09 09:10
Je zou de methode nog kunnen markeren met [SecuritySafeCritical], volgens StackOverflow.

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Dit heeft inderdaad het probleem verholpen! Bedankt voor je hulp!