-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RS1035: The symbol 'Environment' is banned for use by analyzers #4891
Comments
@Scottj1s I'm not seeing a good way for The problematic code passes a string from the caller's assembly to be later used by UndockedRegFreeWinRT (URFW) and MRT. Environment variables are used as a form of 'global variable' within WinAppSDK
I'm inclined to change this to explicitly handle this e.g. change
and in
and change URFW+MRT from This avoids using envvars as globals e.g. if an app doesn't use the C# auto-initializer this avoids malicious actors from setting the envvar to affect behavior. You have any qualms with this change? P.S. Interestingly this EnvVar game only occurs in the auto-initializer for C# but not for C++. This is intentional? |
@Scottj1s Another option is CoreApplication.Properties Property (Windows.ApplicationModel.Core) - Windows apps | Microsoft Learn For example to set the option apps would Windows.ApplicationModel.Core.Application.Properties()["Microsoft.WindowsAppRuntime.BaseDirectory"] = AppContext.BaseDirectory; and in WinAppSDK check/retrieve via the C++ equivalent of Windows.Foundation.PropertyValue value;
HRESULT hr = Windows.ApplicationModel.Core.Application.Properties().Lookup("Microsoft.WindowsAppRuntime.BaseDirectory", &value)
string baseDirectory = (SUCCEEDED(hr) ? value.GetString() : nullptr); In C++ that looks something like auto properties{ winrt::Windows::ApplicationModel::Core::Application::Properties() };
winrt::hstring baseDirectory;
wil::com_ptr<abi::Windows::ApplicationModel::Core::Application::IPropertySet> propertiesAsABI{ properties.as<abi::Windows::ApplicationModel::Core::Application::IPropertySet>() };
winrt::hstring key{ "Microsoft.WindowsAppRuntime.BaseDirectory" };
winrt::Windows::Foundation::PropertyValue value;
const HRESULT hr{ propertiesAsABI->Lookup(key, wil::out_param(value)) };
THROW_HR_IF(hr, hr != E_BOUNDS);
if (SUCCEEDED(hr))
{
baseDirectory = std::move(value);
} |
Describe the bug
Using .NET 9, latest Windows App SDK:
Steps to reproduce the bug
Using .NET 9
Expected behavior
No response
Screenshots
No response
NuGet package version
Windows App SDK 1.6.2: 1.6.241106002
Packaging type
Packaged (MSIX)
Windows version
Windows 11 version 22H2 (22621, 2022 Update)
IDE
Visual Studio 2022
Additional context
No response
The text was updated successfully, but these errors were encountered: