Closed JasonWei512 closed 1 year ago
Error when clicking "Contact the developer" button in settings page:
2023/03/15 21:13:42.991 | ERROR | Unhandled exception|System.TypeInitializationException: The type initializer for 'System.Management.WmiNetUtilsHelper' threw an exception.
---> System.TypeLoadException: Could not load type 'System.StubHelpers.InterfaceMarshaler' from assembly 'System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
at System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointerInternal(IntPtr, Type)
at System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer[TDelegate](IntPtr)
at System.Management.WmiNetUtilsHelper.LoadDelegate[TDelegate](TDelegate&, IntPtr, String)
at System.Management.WmiNetUtilsHelper..cctor()
--- End of inner exception stack trace ---
at System.Management.MTAHelper.IsNoContextMTA()
at System.Management.MTAHelper.CreateInMTA(Type)
at System.Management.ManagementPath.CreateWbemPath(String)
at System.Management.ManagementObjectSearcher..ctor(String, String, EnumerationOptions)
at Hardware.Info.Windows.HardwareInfoRetrieval.GetOs()
at Hardware.Info.HardwareInfo..ctor(Boolean useAsteriskInWMI, Nullable`1 timeoutInWMI)
at EnergyStarX.ViewModels.SettingsViewModel.<>c.<.ctor>b__40_0()
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper, Boolean)
at System.Lazy`1.CreateValue()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread, ExecutionContext, ContextCallback, Object)
--- End of stack trace from previous location ---
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread, ExecutionContext, ContextCallback, Object)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task&, Thread )
--- End of stack trace from previous location ---
at EnergyStarX.ViewModels.SettingsViewModel.ContactTheDeveloper()
at CommunityToolkit.Mvvm.Input.AsyncRelayCommand.AwaitAndThrowIfFailed(Task)
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object)
at Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext.<>c__DisplayClass2_0.<Post>b__0()
--- End of stack trace from previous location ---
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32)
at ABI.Windows.ApplicationModel.Core.IUnhandledErrorMethods.Propagate(IObjectReference)
at Microsoft.AppCenter.Utils.ApplicationLifecycleHelperWinUI.<.ctor>b__0_3(Object sender, UnhandledErrorDetectedEventArgs eventArgs)
Hardware.Info
uses System.Management
, which is incompatible with trimming.
Related: https://github.com/dotnet/runtime/issues/61960
Replaced Hardware.Info
with WmiLight
for fetching hardware info.
Visual Studio App Center SDK uses Newtonsoft.Json
, which is not trimming friendly.
Not sure if telemetry will be affected.
Reverted because it breaks App Center telemetry. https://github.com/JasonWei512/EnergyStarX/issues/14#issuecomment-1477142429
Solve #14 .
Currently the
TrimMode
is set topartial
, sincefull
is too aggressive. Need some time to test and make sure it doesn't break app's functionality.Size comparision
App size is reduced by 50%.
Note
TaskScheduler
is removed from dependencies because it uses COM to interact with Windows Task Scheduler and is incompatible with IL trimming. Instead I useschtasks
get the status of the admin startup schedule task.