Skip to content
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

System.TypeInitializationException : The type initializer for '<Module>' threw an exception. #30

Open
skottmckay opened this issue Jul 27, 2024 · 1 comment

Comments

@skottmckay
Copy link

Describe the bug

Running the SampleMauiApp unit tests in Visual Studio 17.10.4 for the net8.0-windows target fail with an exception.

 SampleMauiApp.UnitTests.FailingTest
   Source: UnitTests.cs line 18
   Duration: 1 ms

  Message: 
System.TypeInitializationException : The type initializer for '<Module>' threw an exception.
---- System.TypeInitializationException : The type initializer for 'WinRT.ActivationFactory`1' threw an exception.
-------- System.Runtime.InteropServices.COMException : Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))

  Stack Trace: 
RuntimeTypeHandle.GetActivationInfo(RuntimeType rt, & pfnAllocator, Void*& vAllocatorFirstArg, & pfnCtor, Boolean& ctorIsPublic)
ActivatorCache.ctor(RuntimeType rt)
RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
Activator.CreateInstance(Type type, Object[] args)
<>c__DisplayClass0_0.<CreateTestClass>b__0() line 42
ReflectionAbstractionExtensions.CreateTestClass(ITest test, Type testClassType, Object[] constructorArguments, IMessageBus messageBus, ExecutionTimer timer, CancellationTokenSource cancellationTokenSource) line 42
----- Inner Stack Trace -----
ActivationFactory`1.ActivateInstance[I]()
DeploymentInitializeOptions.ctor()
AutoInitialize.get_Options() line 44
AutoInitialize.AccessWindowsAppSDK() line 30
cctor()
----- Inner Stack Trace -----
Marshal.ThrowExceptionForHR(Int32 errorCode)
BaseActivationFactory.ctor(String typeNamespace, String typeFullName)
ActivationFactory`1.ctor()
ActivationFactory`1.cctor()

To Reproduce

Cloned the repo.
Loaded DeviceRunners.sln in Visual Studio 17.10.4.
Had to remove tizen from the target frameworks in a few csproj files as that workload can't be installed via VS and it wouldn't find the dotnet workload.

Apart from that no other changes.

Expected behavior

Tests can run

Screenshots

image

Device (please complete the following information)

  • OS: [e.g. Windows/Mac Catalyst/iOS/Android] Windows
  • Version [e.g. 11, 14.2, 12.0] 24H2

Additional context

Add any other context about the problem here.

@skottmckay
Copy link
Author

I see the same error if I run using dotnet test from the SampleMauiApp directory.

If I run SampleMauiApp from VS I am however able to successfully run the tests.

Hopefully that narrows down what is causing the issue when running from Test Explorer or when using dotnet test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant