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

In .NET 5.0 Error #140

Closed
wf-soft opened this issue Jul 13, 2020 · 15 comments
Closed

In .NET 5.0 Error #140

wf-soft opened this issue Jul 13, 2020 · 15 comments
Assignees

Comments

@wf-soft
Copy link

wf-soft commented Jul 13, 2020

Initialization of 'ModernWpf.ThemeResources' threw an exception.' Line number '10' and line position '18'.

@ShankarBUS
Copy link
Contributor

ShankarBUS commented Jul 13, 2020

.NET 5 hmmm, it could be caused due to the WinRT dependency of this library (i.e. to fetch system themes and colors).

One of the breaking changes in .NET 5 is the removal of built-in WinRT support.
It could be resolved if this library depends on

This is due to this library having a copy of the metadata files (.winmd files in the WinMD folder) instead of depending on the said packages

See this issue for reference - Microsoft.Windows.SDK.Contracts - microsoft/CsWinRT/issues/283

May be IDK 🤷‍♂️. Hey @Kinnara, what are your thoughts?

Edit : the Microsoft.Windows.SDK.Contracts package doesn't seem to support .NET 4.5.
Either this library should use the current metadata method (.winmd files) only for .NET 4.5 or completely drop support for .NET 4.5

@ShankarBUS
Copy link
Contributor

ShankarBUS commented Jul 13, 2020

⚠⚠ Important ⚠⚠ :
For .NET 5, using Microsoft.Windows.SDK.NET is the only way to consume WinRT APIs.
But.... there is a problem with it, the Microsoft.Windows.SDK.NET.dll is a huge file (~25 MB) [will be unpleasant to user 🤦‍♂️]

Hey @wf-soft, I have the fixed the bug in my fork (ShankarBUS/ModernWpf) and its working for me. So do this :

Hey @Kinnara,
Is this the real issue?

@mlivernoche
Copy link

mlivernoche commented Jul 13, 2020

@ShankarBUS I can confirm that your branch has worked. I haven't done extensive testing, but there is no longer any crash on startup.

@Kinnara Here's the stack traces I get when running without these fixes.

The type initializer for 'ModernWpf.ThemeManager' threw an exception.
at ModernWpf.ThemeManager.get_Current() in ModernWpf\ThemeManager.cs:line 698
at ModernWpf.ThemeResources.EndInit() in ModernWpf\ThemeResources.cs:line 214
at ModernWpf.ThemeResources.System.ComponentModel.ISupportInitialize.EndInit() in ModernWpf\ThemeResources.cs:line 238
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)

Inner Exception
The type initializer for 'ModernWpf.ColorsHelper' threw an exception.
at ModernWpf.ThemeManager..cctor() in ModernWpf\ThemeManager.cs:line 167

Inner Exception
Operation is not supported on this platform. (0x80131539)
at ModernWpf.ColorsHelper.ListenToSystemColorChanges() in ModernWpf\Helpers\ColorsHelper.cs:line 154
at ModernWpf.ColorsHelper..ctor() in ModernWpf\Helpers\ColorsHelper.cs:line 34
at ModernWpf.ColorsHelper..cctor() in ModernWpf\Helpers\ColorsHelper.cs:line 40

EDIT:

dotnet --version
5.0.100-preview.6.20318.15

ModernWpf 0.9.0
I also confirmed this happened on 0.9.1.

@ShankarBUS
Copy link
Contributor

Hey @mlivernoche, thanks for the verification. I got the exact same exception before. There won't be any bug anymore since the only problem seemed to be with how .NET 5 interact with WinRT and not within this library. So we can believe nothing wrong will happen 😅. My fix is hard coded for .NET 5, it should modified to include .NET 6, etc when they arrive.

@wf-soft
Copy link
Author

wf-soft commented Jul 29, 2020

@ShankarBUS Great. I've been using this library. It's very easy to use

@Kinnara
Copy link
Owner

Kinnara commented Aug 2, 2020

.NET 5.0 support has been added in the latest preview. Thank you all for your info and help!

@ShankarBUS
Copy link
Contributor

ShankarBUS commented Sep 10, 2020

Hey @Kinnara

Incase you're not aware, the WinRT interop mechanism has been again changed in .NET 5 Preview 8

See https://blogs.windows.com/windowsdeveloper/2020/09/03/calling-windows-apis-in-net5/

@Kinnara
Copy link
Owner

Kinnara commented Sep 13, 2020

@ShankarBUS Didn't know that. Thanks for the info!

@ShankarBUS
Copy link
Contributor

@Kinnara, .NET 5 is expected to be released soon. I hope you'd polish this library for it.

@Kinnara
Copy link
Owner

Kinnara commented Sep 14, 2020

@Kinnara, .NET 5 is expected to be released soon. I hope you'd polish this library for it.

Thanks for the reminder, I'll try.

@Kinnara
Copy link
Owner

Kinnara commented Sep 23, 2020

v0.9.2 should now have proper .NET 5 support (hopefully).

@Kinnara Kinnara closed this as completed Sep 23, 2020
@jonasnordlund
Copy link

I'm getting this again with the release version of .NET 5 and ModernWpf 0.9.2.

TypeInitializationException: The type initializer for 'ModernWpf.ThemeManager' threw an exception.
(Inner Exception) TypeInitializationException: The type initializer for 'ModernWpf.ColorsHelper' threw an exception.
(Inner Exception) System.Windows.Markup.XamlParseException: ''Initialization of 'ModernWpf.ThemeResources' threw an exception.' Line number '9' and line position '18'.'

@ShankarBUS
Copy link
Contributor

@jonasnordlund,

Is your target framework in this format net5.0-windows10.0.x.0. (x is target Windows 10 SDK)?

If not you may get those errors.

@jonasnordlund
Copy link

jonasnordlund commented Nov 17, 2020

@ShankarBUS Thank you, no I didn't set it to the specifik SDK version. Will this (e.g. net5.0-windows10.0.18362.0) make our application require Windows 10 Version 1903? I've chosen this library part because it has pretty low system requirements but this target framework makes me concerned?

@ShankarBUS
Copy link
Contributor

No no no, it just means that your app can use APIs from the Windows 10 1903 SDK. It just the SDK you target! Not the minimum supported OS.

This library has internal checks the Windows versions which the app runs to prevent errors on older Windows versions.

It will run on Windows 7 & above with no problems at all! You don't have to worry about anything!

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

5 participants