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 9241101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:18:33+00:00 2026-06-18T08:18:33+00:00

During a .NET 4.0 -> .NET 4.5 application migration process I’ve discovered an extremely

  • 0

During a .NET 4.0 -> .NET 4.5 application migration process I’ve discovered an extremely strange behavior. I’ve been able to track this issue down to this short code snippet:

class Program
{
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    public static extern int GetSystemMetrics(int nIndex);

    static void Main(string[] args)
    {
        const int CXFRAME = 0x20;
        const int CYFRAME = 0x21;

        var dx = GetSystemMetrics(CXFRAME);
        var dy = GetSystemMetrics(CYFRAME);

        Console.WriteLine("{0}x{1}", dx, dy);
        Console.ReadKey();
    }
}

When compiled with Target Framework = 4.0 (and also 2.0, 3.0, 3.5), it outputs 8x8

When compiled with Target Framework = 4.5, it outputs 4x4

Running this sample with MSVS2012 debugger also always outputs 4x4 (with any target framework).

Other options (target framework profile, target platform, enabling/disabling Aero) do not affect the result, the only things that change the output are target framework and running with debugger. I’ve been able to reproduce this issue on 3 computers, unfortunately they are almost identical in terms of installed software:

  • Windows 7 Ultmate SP1 (russian, all updates installed) with MSVS2012 (english/rusian) Update 1
  • Windows 8 (on virtual machine)

Currently I’m thinking about patching some .NET classes (SystemParameters for example), which call GetSystemMetrics() using reflection, but I’m not sure how to get correct metric values.

Questions:

  • Am I missing something? How can GetSystemMetrics() be affected by target framework?
  • Is there any way to call GetSystemMetrics() from .NET 4.5 app and get correct results?

I’m open to any suggestions on fixing this issue. Also, if you cannot reproduce the issue, please leave a short system description in comments.

  • 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-18T08:18:34+00:00Added an answer on June 18, 2026 at 8:18 am

    According to Microsoft, this is by-design.

    See here for full details:

    • The SystemParameters.WindowResizeBorderThickness seems to return incorrect value – Microsoft Connect (no archived version available)
    • Regression: ::GetSystemMetrics delivers different values – Microsoft Connect (archived)

    Despite MS saying it’s "by design", I still think it’s a bug!

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

Sidebar

Related Questions

My ASP.Net application used to restart unpredictably during requests, ruining my state, session data
I am working on an asp.net application which errors only during the first time
I've tried updating my application's .config file during installer ( via a .NET Installer
I'm in the process of moving a large classic ASP application to ASP.NET MVC
My .NET application is starting a second process with Process.Start(.\path\to\process.exe) Is there a way
I have a vb.net application which does some processing. This processing can take a
How can I check which methods are called during a .NET application startup? I
The situation is this: I have a Setup project created for my .NET application,
I am so used to attach a process when debugging ASP.NET application in .NET
I have an ASP.Net application that performs some database initialization during Application_Start in Global.asax.

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.