Search
Closed
as By Design Help for as By Design

2
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 458218
Opened: 5/26/2009 12:18:02 AM
Access Restriction: Public
1
Workaround(s)
0
User(s) can reproduce this bug
Sytem.Environmentクラスを用いてOSのメジャーバージョンを取得する処理で、作成されたexeファイルにWindows XP互換モードを設定した際の挙動がWin32 APIのそれと異なるようです。
実験として、C++/CLIにて以下のようなコードを作成しました。

#include "stdafx.h"
#include <shlobj.h>

using namespace System;

int GetOsMajorVersionByDotNet()
{
    System::OperatingSystem^ os = System::Environment::OSVersion;
    if (os->Platform == PlatformID::Win32NT)
    {
        return os->Version->Major;
    }
    return -1;
}

int GetOsMajorVersionByApi()
{
    OSVERSIONINFO osVerInfo;
    unsigned long dwNumber = 0;
    ::ZeroMemory(&osVerInfo, sizeof(OSVERSIONINFO));
    osVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

    if (GetVersionEx(&osVerInfo) == FALSE)
    {
        return -1;    }

    return osVerInfo.dwMajorVersion;
}


int main(array<System::String ^> ^args)
{
    Console::WriteLine("GetOsMajorVersionByApi returns: {0}", GetOsMajorVersionByApi());
    Console::WriteLine("GetOsMajorVersionByDotNet returns: {0}", GetOsMajorVersionByDotNet());    
    return 0;
}
Windows Vistaにて、上記のソースコードを基に作成したexeファイルに対してファイルのプロパティよりWindows XP互換モードを設定したうえで、exeファイルを実行すると、以下のように出力されます。
GetOsMajorVersionByApi returns: 5
GetOsMajorVersionByDotNet returns: 6

なお、互換モードをWindows NTに設定すると、今度は両方とも4を返しました。Windows XPに設定したときのEnvironmentクラスの返す値だけがなにかおかしいように思います。
また、同じコードをWindows 7 RC1にてVisual Studio 2010 Beta/.net Framework 4.0を使用してビルド・実行すると今度はどちらも(Windows XPの設定で)5を返しました。

これはつまり、現行では互換モードにおけるEnvironmentクラスの動作に不具合があるように思われます。見解をお願いいたします。
Details (expand)
製品言語
日本語
バージョン
.NET Framework 3.5 SP1
オペレーティング システム
Windows Vista
オペレーティング システム言語
日本語
再現の手順
説明文中のコードを/clrでコンパイルして作成されたファイルをWindows VistaにてWindows XP互換モードに設定して実行
実際の結果
Win32 API経由で取得できるOSバージョンは5となるが、Environmentクラスでは依然として6のままになる。
期待した結果
Windows XP互換モードでは両方とも5を得る。
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 5/31/2009 at 6:06 PM

この度は、フィードバックをお送りいただき、誠にありがとうございます。 現在、お送りいただきました報告内容に基づき問題を調査中ですので、しばらくお待ちください。 よろしくお願いいたします。

[Description]
When you use the System.Environment class to get a major OS version and set Window XP compatibility mode to the exe file created, its behavior seems different from Win32 API. As an experiment, I created the below code using C++/CLI.

#include "stdafx.h"
#include <shlobj.h>

using namespace System;

int GetOsMajorVersionByDotNet()
{
    System::OperatingSystem^ os = System::Environment::OSVersion;
    if (os->Platform == PlatformID::Win32NT)
    {
        return os->Version->Major;
    }
    return -1;
}

int GetOsMajorVersionByApi()
{
    OSVERSIONINFO osVerInfo;
    unsigned long dwNumber = 0;
    ::ZeroMemory(&osVerInfo, sizeof(OSVERSIONINFO));
    osVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);

    if (GetVersionEx(&osVerInfo) == FALSE)
    {
        return -1;    }

    return osVerInfo.dwMajorVersion;
}


int main(array<System::String ^> ^args)
{
    Console::WriteLine("GetOsMajorVersionByApi returns: {0}", GetOsMajorVersionByApi());
    Console::WriteLine("GetOsMajorVersionByDotNet returns: {0}", GetOsMajorVersionByDotNet());    
    return 0;
}
On Windows Vista, when you create an exe file based on the above source code, go to its Properties to set compatibility mode to Windows XP, and then run it, the following results are output.
GetOsMajorVersionByApi returns: 5
GetOsMajorVersionByDotNet returns: 6

For your information, when compatibility mode is set to Windows NT, both return '4.' I think something is weird with the value returned by the Environment class when compatibility mode is set to Windows XP. In addition, when you build and run the same code on Windows 7 RC1 installed with Visual Studio 2010 Beta and .NET Framework 4.0 (compatibility mode is set to Windows XP), both return '5.'

Therefore, there seems to be a bug on the current behavior of the Environment class in compatibility mode. Your opinion is greatly appreciated.

[Repro Steps]
Compile the code in the above description with /clr, set compatibility mode to Windows XP, and run the created file on Windows Vista.

[Actual Results]
While the OS version obtained through Win32 API is '5,' the Environment class still returns '6.'

[Expected Results]
When compatibility mode is set to Windows XP, both return '5.'

Posted by Microsoft on 6/2/2009 at 11:43 PM
Thanks for your feedback. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Posted by Microsoft on 6/3/2009 at 2:18 AM

(こちらは、[投稿者: Microsoft、投稿日時: 2009/06/02 23:43] の和訳になります。)

フィードバックをお寄せいただき、ありがとうございます。 こちらのバグに関しましては、該当する機能を専門で担当している製品チームに報告させていただきます。 今後は、同チームが問題を再調査し、次期リリースでの修正について判断する予定です。 よろしくお願いいたします。

Visual Studio 製品チーム

Posted by Microsoft on 6/4/2009 at 4:31 PM
Hello wakimoto,
Thank you for the post on System.Environment.OSVersion not respecting the Compatibility tab. This behavior is by design with the .NET Framework as the runtime is excluded from the OS AppCompat shims. I will follow up with our MSDN documentation owners to make sure the documentation is changed to be more clear in this area.

Thanks,
Josh Free
Base Class Library Development
Posted by Microsoft on 6/4/2009 at 6:03 PM

(こちらは、[投稿者: Microsoft、投稿日時: 2009/06/04 16:31] の和訳です。)

wakimoto さん、こんにちは。

[互換性] タブの設定を正確に反映しない System.Environment.OSVersion に関するご投稿をいただき、ありがとうございます。 この動作は、.NET Framework の仕様となっています。 これは、ランタイムが OS の AppCompat シムから除外されているためです。 私は、MSDN ドキュメントの担当者に連絡し、この分野の記述をより明確な形に変更させていただきたいと思います。 よろしくお願いいたします。

Josh Free
基本クラス ライブラリ開発

Posted by wakimoto on 6/4/2009 at 6:47 PM
Hi, Josh Free-san

回答ありがとうございます。

しかしながら現行の動作が仕様だとすると、以下の点において不合理があるよううに思われます。
・(現実使うことはあり得ませんが)互換性をNT4にした場合の動作→互換モードの設定値を得る
・.net Framwork 4.0 Beta on Windows 7(Build7037) 上での挙動→互換モードの設定値を得る
・.net Framwork 3.5 on Windows 7(Build7037) 上での挙動→互換モードの設定値が無視される

現行の.net 3.5の仕様を通すならば、、.net 4.0の挙動の方が今後のリリースで変更される可能性の方が高いと考えるべきでしょうか?

Posted by Microsoft on 6/4/2009 at 10:06 PM

(こちらは、wakimoto さんが 2009/06/04 18:47 に投稿されたメッセージの英訳です。)

Hi Josh,

Thank you for your reply. However, given the current behavior is by design, there seems to be something unreasonable with the following behaviors:

- When compatibility mode is set to Windows NT 4 (although this is probably never used) -> Compatibility mode setting is respected.
- .NET Framework 4.0 Beta on Windows 7 (Build7037) -> Compatibility mode setting is respected..
- .NET Framework 3.5 on Windows 7 (Build7037) -> Compatibility mode setting is not respected.

If the current .NET 3.5 design remains, should I consider there’s a high possibility the .NET 4.0 behavior may be changed in the future releases?

Posted by Microsoft on 6/5/2009 at 10:21 AM
Hi wakimoto,
Thank you for reporting the .NET Framework 4.0 Beta 1 Compatibility mode inconsistency. This is a known Beta 1 issue and it is being investigated by the appropriate teams.

Thank you again,
Josh Free
Base Class Library Development
Posted by Microsoft on 6/7/2009 at 6:30 PM

(こちらは、[投稿者: Microsoft、投稿日時: 2009/06/05 10:21] の和訳です。)

wakimoto さん、こんにちは。

.NET Framework 4.0 Beta 1 の互換モードの不一致に関するご報告をいただき、ありがとうございます。 こちらは、Beta 1 の既知の問題となっており、現在、担当チームが調査に当たっています。 よろしくお願いいたします。

Josh Free
基本クラス ライブラリ開発

Posted by wakimoto on 6/7/2009 at 7:47 PM
Hi Josh,

仕様としての疑問を感じますが、ひとまず了解いたしました。それではこちらといたしましては、互換性モードを考慮する目的では、プラットフォーム呼び出しによるバージョン取得で対応したいと思います。

ありがとうございました。
Posted by Microsoft on 6/7/2009 at 9:53 PM

(こちらは、wakimoto さんが 2009/06/07 19:47 に投稿されたメッセージの英訳です。)

Hi Josh,

I still cannot but question the design, but I understand for now. So I’ll try to use platform invoke to retrieve OS version information when using compatibility mode. Thank you very much.