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

failed with exception ='System.TypeLoadException on .NETFramework 4.6.2 #946

Closed
bunki-tou opened this issue Feb 17, 2021 · 30 comments
Closed
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@bunki-tou
Copy link

bunki-tou commented Feb 17, 2021

Description
My WebView2 Application(WinForms) failed with exception ='System.TypeLoadException on .NETFramework 4.6.2.

*stack trace
System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.Architecture' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.LoadWebView2LoaderDll()
at Microsoft.Web.WebView2.Core.CoreWebView2Environment.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Web.WebView2.WinForms.WebView2.d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at biz.harmomedicalinstitution.cardreader.view.MainForm.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.b__6_0(Object state)

Version
SDK: 1.0.7.5.50
Runtime: both 88.0.705.68 and 87.0.664.75
Framework: WinForms .NETFramework4.6.2 (update from 4.5.1)
OS: WindowsServer2012R2 (hyper-v)
hostOS:Windows10Pro 20H2
WebView2Sample.zip

Repro Steps

  1. update .NetFramework vesion to 4.6.2 from 4.5.1. using Web Installer.
  2. Evergreen Standalone Install
  3. My WebView2 Application starts.
  4. failed TypeLoadException .

Screenshots
image

Additional context
#864 is similar to this.

AB#31786125

@bunki-tou bunki-tou added the bug Something isn't working label Feb 17, 2021
@champnic
Copy link
Member

Hey @bunki-tou - thanks for the bug report. It looks like we may have inadvertently taken a dependency on an API not available in .NET 4.6.2. Can you try 4.7.1 and see if this error goes away? If it does that will confirm my suspicion and we'll have to investigate fixes on our end.

@champnic champnic self-assigned this Feb 18, 2021
@bunki-tou
Copy link
Author

bunki-tou commented Feb 18, 2021

@champnic Thanks for reply to my report.
I tried to do on updating 4.7.1 , and this error goes away. I think that webview2 may be not available in .NET 4.6.2, because it's using 'System.Runtime.InteropServices.Architecture' .

@juergenil
Copy link

Same behaviour here. We have a customer with some Windows 10 2015 LTSB installations. Highest framework version, which can be installed is 4.6.2. So he can't update to 4.7.1. As a result WebView2 ist not usable in this environment, although documentation states, it should be possible.

@champnic champnic added the tracked We are tracking this work internally. label Feb 19, 2021
@champnic
Copy link
Member

That's disappointing, sorry you're blocked by this. I've added this bug to our backlog and we'll try and get this fixed soon!

@bunki-tou
Copy link
Author

Thanks for confirmig quickly. I'm looking forward to fix this!

@paolodel
Copy link

paolodel commented May 4, 2021

Hi, I have the same need about WebView2. We have some equipments with Windows 10 2015 LTSB.
I have tried to use prerelease version 1.0.865, now exception is received through CoreWebView2InitializationCompleted event and it changed to
Error_WebView2
Dependency on .NET 4.7 is still present

@champnic
Copy link
Member

champnic commented May 4, 2021

Thanks for the update - I've added this info and re-opened the bug.

@dianaqu
Copy link
Contributor

dianaqu commented May 13, 2021

Hi @bunki-tou,

Going back to read your description. It seems you mean that version 4.5.1 was working for you and only updating to 4.6.2 caused the issue? Would you mind confirm that it works for 4.5.1?

@juergenil
Copy link

@dianaqu The cause of the TypeLoadExceptions, shown in the previous StackTraces, are missing types System.Runtime.InteropServices.Architecture and System.Runtime.InteropServices.RuntimeInformation. Both were introduced in .NET Framework 4.7.1. So for my understanding it's impossible to run neither with 4.5.1 nor with 4.6.2.

@bunki-tou
Copy link
Author

@dianaqu
No, it's not working on 4.5.1.
So, this exception causes not only updating to 4.6.2.

@Tennyleaz
Copy link

I also got TypeLoadExceptions on .Net 4.6.2, webview2 version 1.0.818.41.
Only solution now is to downgrade webview2 version to 0.9.579-prerelease.

@dianaqu
Copy link
Contributor

dianaqu commented Jun 8, 2021

Hi folks on this thread.
I have a potential fix, but I been having trouble obtaining a repo machine. Would anyone on the thread mind helping verify the fix?
test.zip

@Tennyleaz @bunki-tou @juergenil @paolodel

@bunki-tou
Copy link
Author

@dianaqu Thank you.
I verified this package, but this also occurred TypeLoadException which is the same exception before the fix

************** 例外テキスト **************
System.TypeLoadException: アセンブリ 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' から型 'System.Runtime.InteropServices.Architecture' を読み込めませんでした。
   場所 Microsoft.Web.WebView2.Core.CoreWebView2Environment.LoadWebView2LoaderDll()
   場所 Microsoft.Web.WebView2.Core.CoreWebView2Environment.<CreateAsync>d__3.MoveNext()
--- 直前に例外がスローされた場所からのスタック トレースの終わり ---
   場所 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   場所 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   場所 WebView2_Sample.Form1.<WebView2Init>d__1.MoveNext()
--- 直前に例外がスローされた場所からのスタック トレースの終わり ---
   場所 System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)

@yudaming
Copy link

yudaming commented Jul 9, 2021

image
System.TypeLoadException:“未能从程序集“mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”中加载类型“System.Runtime.InteropServices.RuntimeInformation”。”

image
image

@dianaqu
Copy link
Contributor

dianaqu commented Jul 16, 2021

@bunki-tou @juergenil @paolodel @yudaming
Hi folks, I been having trouble obtain a repo machine, is there anyway possible any of you share a repo VM for me to test around it?

@gpsaliola
Copy link

Hello,
I've the same issue with webview2 latest version (1.3.143.57 ) on Windows 7 and Framework 4.5.
The same app works fine on Windows 10.
Can somebody help me please?
Thank you.

@dianaqu
Copy link
Contributor

dianaqu commented Jul 20, 2021

Hi @gpsaliola , Do you happen to have a repo machine that I can try to access?

@gpsaliola
Copy link

gpsaliola commented Jul 20, 2021

I'm sorry, no. I'm tested my app on a virtual machine created with VirtualBox.
On my main machine (Windows 10) works fine.
May be a problem concerned with missing "Extended Security Updates for Windows 7"?

@bunki-tou
Copy link
Author

bunki-tou commented Jul 21, 2021

@dianaqu I'm sorry. I can't share my repo VM , because many development Apps were installed in this VM.

@juergenil @paolodel @yudaming
Can you share your repo VM to @dianaqu ?

@paolodel
Copy link

@dianaqu, Sorry, I can't give you access to our single equipment with Windows 10 2015 LTSB.
It's inside our R&D department and it's not accessible from outside.
Unfortunately I have no repo VM, only this real equipment.

@gpsaliola
Copy link

I've create a simple example that runs on Windows 10 but crash in Windows 7.
You can download here: https://www.okmap.org/test.zip.
Thank you!

@gpsaliola
Copy link

I saw on the Microsoft site that the RuntimeInformation class (which fails to load) has Framework 4.7.1 or higher as prerequisites. Could this be the problem since my app was compiled for Framework 4.5?

@champnic
Copy link
Member

champnic commented Jul 23, 2021

That is indeed the crux of the issue, so we're working on a workaround for those RuntimeInformation properties that gives us the same info. The problem is not that your app was compiled for 4.5, but rather that it's being run with a .NET runtime that doesn't have the RuntimeInformation implementation (like 4.5 or 4.6). A workaround to get unblocked is to install a newer .NET runtime on the machines, or yes, to target a newer framework (these are not always options though, as described by other users above).

@gpsaliola
Copy link

Thanks for the explanation.
I switched to 4.7.2 and everything seems to be working fine.
However I have some dlls that I have left at 4.5.
I wonder if this is an acceptable practice; do you think it is better that I also recompile all the dlls to version 4.7.2?
One last question ... How can you determine if WebView2 is installed (with Inno for example)?

@champnic
Copy link
Member

champnic commented Jul 26, 2021

@gpsaliola Please see step 1) here:
https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#online-only-deployment
You can check a regkey or use GetAvailableCoreWebView2BrowserVersionString API to determine if WebView2 is installed.

It should be fine to have mixed dll versions. The only issue would be if you tried to run your app on a machine that only had a runtime < 4.7.2 and wasn't connected to the internet or able to update their runtime.

@gpsaliola
Copy link

thanks, this solves my problem.
I wrote a little script for Inno Setup, it might be useful for other developers:

function WebView2Installed(): Boolean;
  var
    pv: String;
    key: String;
  begin
    Result := False;
    if IsWin64 then begin
      key := 'SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}';
    end else
    begin
      key := 'SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}';
    end;
    if RegQueryStringValue(HKEY_LOCAL_MACHINE, key, 'pv', pv) then begin
      Result := True;
    end;
  end;

@drearyrainDeng
Copy link

we got the same error . just netframe 4.6.1 be installed on win10 1607 TLSB,
image

@champnic champnic mentioned this issue Oct 8, 2021
@champnic
Copy link
Member

This is fixed in the newest SDK package 1.0.1056-prerelease. Thanks!

@superpapa
Copy link

@champnic
Excuse me
When will the new version 1.0.1056 ,not prerelease be released on nuget?

@champnic
Copy link
Member

champnic commented Jan 5, 2022

@superpapa This should be available in 1.0.1072.* which is coming out later this week or early next. Thanks!

@novac42 novac42 closed this as completed Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests