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.
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:
Heeft iemand een idee hoe dit netjes op te lossen is, zodat de functie toch gebruikt kan worden?
Alvast bedankt voor jullie hulp!
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!