The type initializer for 'Windows.ApplicationModel.Core.CoreApplication' threw an exception.
- Dominant language
- C#
- Stars
- 7.2k
- Forks
- 798
- PR merge metrics
- No merged PRs in 30d
Description
Seen once in local test runs. Likely due to `System.Reactive\Internal\HostLifecycleNotifications.Windows.cs` accessing `CoreApplication.*` and triggering execution of the static constructor.
```
Test run for D:\Projects\reactive\Rx.NET\Source\tests\Tests.System.Reactive\bin\Debug\net5.0-windows10.0.19041\Tests.System.Reactive.dll (.NETCoreApp,Version=v5.0)
Microsoft (R) Test Execution Command Line Tool Version 16.8.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:03.24] ReactiveTests.Tests.SelectManyTest.SelectManyWithIndex_QueryOperator_ErrorOuter [FAIL]
Failed ReactiveTests.Tests.SelectManyTest.SelectManyWithIndex_QueryOperator_ErrorOuter [91 ms]
Error Message:
System.TypeInitializationException : The type initializer for 'Windows.ApplicationModel.Core.CoreApplication' threw an exception.
---- System.ArgumentException : Value does not fall within the expected range.
Stack Trace:
at Windows.ApplicationModel.Core.CoreApplication._ICoreApplication..ctor()
----- Inner Stack Trace -----
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at WinRT.BaseActivationFactory..ctor(String typeNamespace, String typeFullName)
at Windows.ApplicationModel.Core.CoreApplication..cctor()
```
Maybe there's some flakiness in `Windows.ApplicationModel.Core` that needs to be investigated. Looking at the code, there seems to be some pretty liberal exception handling that could explain getting to the `ThrowExceptionForHR` call under some circumstances:
```csharp
string text = typeNamespace;
while (true)
{
try
{
activationFactory = DllModule.Load(text + ".dll").GetActivationFactory(runtimeClassId);
_IActivationFactory = activationFactory.Item1;
if (_IActivationFactory != null)
{
return;
}
}
catch (Exception)
{
}
int num = text.LastIndexOf(".");
if (num <= 0)
{
Marshal.ThrowExceptionForHR(item);
}
text = text.Remove(num);
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.