SteveSandersonMS / WebWindow

.NET Core library to open native OS windows containing web UI on Windows, Mac, and Linux. Experimental.
Apache License 2.0
1.98k stars 215 forks source link

System.TypeInitializationException Message=The type initializer for 'WebWindows.WebWindow' threw an exception. #1

Closed ghost closed 4 years ago

ghost commented 4 years ago

When running any of the sample apps on Windows 10 I'm getting this exception:

System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'WebWindows.WebWindow' threw an exception. Source=WebWindow StackTrace: at WebWindows.WebWindow..ctor(String title) at VueFileExplorer.Program.Main(String[] args) in C:\repos\Karl Personal\WebWindow\samples\VueFileExplorer\Program.cs:line 14

Inner Exception 1: DllNotFoundException: Unable to load DLL 'WebWindow.Native' or one of its dependencies: The specified module could not be found. (0x8007007E)

Thank you for looking into this.

arpadbarta commented 4 years ago

Did you select x64 as your target platform? As @SteveSandersonMS has mentioned in his blog post it will not compile with Any CPU, at least the native part.

SteveSandersonMS commented 4 years ago

Interesting. I don't know why this would happen.

Can anyone else confirm whether the VueFileExplorer works or doesn't work for them on Windows?

arpadbarta commented 4 years ago

It does work, however the WebWindow.Native needs to be built first, since it is a dependency. Oddly I can't break the build anymore. It builds and runs with all platforms... Not sure what did I do...

VictorioBerra commented 4 years ago

Same error, I am unable to get it working.

I did

dotnet new console --name Test1 cd Test1 dotnet add package WebWindow -v 0.1.0-20191118.2

Edit Program.cs paste into Main(...):

    var window = new WebWindow("My super app");
    window.NavigateToString("<h1>Hello, world!</h1> This window is from a .NET Core app.");
    window.WaitForExit();

dotnet run

PS C:\Users\me\Desktop\Test1> dotnet run
Unhandled exception. System.TypeInitializationException: The type initializer for 'WebWindows.WebWindow' threw an exception.
 ---> System.DllNotFoundException: Unable to load DLL 'WebWindow.Native' or one of its dependencies: The specified module could not be found. (0x8007007E)
   at WebWindows.WebWindow.WebWindow_register_win32(IntPtr hInstance)
   at WebWindows.WebWindow..cctor()
   --- End of inner exception stack trace ---
   at WebWindows.WebWindow..ctor(String title)
   at Test1.Program.Main(String[] args) in C:\Users\me\Desktop\Test1\Program.cs:line 10

OS Name Microsoft Windows 10 Enterprise Version 10.0.18362 Build 18362 Processor Intel(R) Core(TM) i7-8650U

SteveSandersonMS commented 4 years ago

Are you running an x86 version of .NET Core?

VictorioBerra commented 4 years ago

Yes 64 bit

SteveSandersonMS commented 4 years ago

OK, I don't know what the issue is then. If you find out, it would be great if you could let us know, especially if you also know how this can be fixed in the library.

VictorioBerra commented 4 years ago

Adding more info. Just tried it on my home PC and same error. dotnet --info output:

PS C:\Users\me\Downloads\Test1> dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support):
  Version: 3.0.0
  Commit:  7d57652f33

.NET Core SDKs installed:
  1.0.0-preview2-003131 [C:\Program Files\dotnet\sdk]
  1.1.0 [C:\Program Files\dotnet\sdk]
  2.0.2 [C:\Program Files\dotnet\sdk]
  2.0.3 [C:\Program Files\dotnet\sdk]
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.105 [C:\Program Files\dotnet\sdk]
  2.1.201 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.401 [C:\Program Files\dotnet\sdk]
  2.1.402 [C:\Program Files\dotnet\sdk]
  2.1.502 [C:\Program Files\dotnet\sdk]
  2.1.505 [C:\Program Files\dotnet\sdk]
  2.1.602 [C:\Program Files\dotnet\sdk]
  2.1.604 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.2.100 [C:\Program Files\dotnet\sdk]
  2.2.101 [C:\Program Files\dotnet\sdk]
  2.2.105 [C:\Program Files\dotnet\sdk]
  2.2.401 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

OS Name Microsoft Windows 10 Pro Version 10.0.18362 Build 18362 Processor Intel(R) Xeon(R) CPU E3-1231 v3 @ 3.40GHz, 3401 Mhz, 4 Core(s), 8 Logical Processor(s)

ghost commented 4 years ago

@arpadbarta I didn't build the WebWindow project. I used the NuGet package for the samples solution. I'm home now and will try again on my home system.

ghost commented 4 years ago

See the attached image. I tried building and publishing on Windows 10 x64. No joy. I don't know how to debug C++ and have not installed that workload. I'm sure there is an explanation. Wish I knew more. Hope this helps.

2019-11-18_18-16-35

Code-DJ commented 4 years ago

I had the same issue. I had to install MSVC v142 - VS2019 C++ x64/x86 build tools (v14.23) to get this to work.

You can do this from VS 2019 Installer > Modify > Individual Components.

ghost commented 4 years ago

@Code-DJ did you rebuild WebWindow or do you need the tools to build the Samples apps?

ghost commented 4 years ago

The line of code pointed to by the arrow is where the exception is being thrown.

2019-11-18_18-38-11

Code-DJ commented 4 years ago

@kdawg1406 I just created a test .NET Core Console app. Added the WebWindow package, put the following lines in Main:

            var window = new WebWindow("My super app");
            window.NavigateToString("<h1>Hello, world!</h1> This window is from a .NET Core app.");
            window.WaitForExit();

Didn't try the sample apps but looks like we need the build tools even for your own sample/test apps.

ghost commented 4 years ago

@Code-DJ thank you, I'm installing the build tools now.

ghost commented 4 years ago

@Code-DJ @SteveSandersonMS I'm still getting the same exception after installing the build tools and creating a .NET Core Console app. I added the NuGet package as Code did.

I built using x64.

ConsoleApp3.exe Unhandled exception. System.TypeInitializationException: The type initializer for 'WebWindows.WebWindow' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'WebWindow.Native' or one of its dependencies: The specified module could not be found. (0x8007007E) at WebWindows.WebWindow.WebWindow_register_win32(IntPtr hInstance) at WebWindows.WebWindow..cctor() --- End of inner exception stack trace --- at WebWindows.WebWindow..ctor(String title) at ConsoleApp3.Program.Main(String[] args) in C:\Code\vs2019\ConsoleApp3\ConsoleApp3\Program.cs:line 7

[YOLO] Mon 11/18/2019 18:59:04.60 C:\Code\vs2019\ConsoleApp3\ConsoleApp3\bin\Debug\netcoreapp3.0

ghost commented 4 years ago

@SteveSandersonMS the date difference on these files is 2 months. Is there a chance one of them is incorrect?

image

Code-DJ commented 4 years ago

@kdawg1406 the dates are the same on my machine.

Both Any CPU and x64 works for me. I think the x64 build requirements are for building the WebWindow.Native project not for projects that use it.

Just to confirm:

  1. Created a .net core 3.0 console project
  2. Right clicked on dependencies, Manage NuGet packages and added preview version of WebWindow package.
  3. In Main, added the Hello World code from above.
  4. Before installing build tools, I was getting the same error as you. After installing the build tools, I am able to run the solution without errors.
SteveSandersonMS commented 4 years ago

OK, I tracked down the issue. It's because the windows DLL had been built in Debug mode, not Release mode. In Debug mode, it can only run if you have some VC++ DLLs on your machine (specifically, the Windows 10 SDK).

I'm changing the prebuilt binary to be a Release build now so it won't require you to have extra stuff on the machine.

ghost commented 4 years ago

@SteveSandersonMS you are the MAN! I'm doing a Lunch and Learn at work Wednesday and am JUICED to show off this work.

You'll let us know when the NuGet package is updated?

ghost commented 4 years ago

@Code-DJ that is exactly the steps I followed. No clue why it didn't work for me.

This is great feedback for Steve, love Blazor!

Code-DJ commented 4 years ago

Got the latest package update that @SteveSandersonMS just pushed. Uninstalled the build tools. Verified that it works correctly.

SteveSandersonMS commented 4 years ago

Great! The new version is 0.1.0-20191119.2 BTW.

Closing now as fixed. Thanks for reporting it.

ghost commented 4 years ago

@SteveSandersonMS now getting this exception with two of my projects:

An unhandled exception of type 'System.AccessViolationException' occurred in WebWindow.dll Attempted to read or write protected memory. This is often an indication that other memory is corrupt. occurred

Not sure what is going.

ghost commented 4 years ago

This is what happens when I launch the Console App Code-DJ recommend in the above thread.

image

ghost commented 4 years ago

@SteveSandersonMS this is what the Sample Vue app does on start up.

image

ghost commented 4 years ago

@Code-DJ what version of .NET Core are you targetting. I'm targetting the .NET Core 3.0 RTM release.

I'm using Visual Studio 2019 16.3.9

I've un-stalled the build tools.

I wonder what the differences are between our systems???

ghost commented 4 years ago

@Code-DJ @SteveSandersonMS I just installed the Chrome Edge browser beta and it's now working!

distantcam commented 4 years ago

Just had the same problem as @kdawg1406, and the same fix (installing Edge beta) worked for me. Might be worth adding to the readme that the Edge beta needs to be installed on Windows.

ghost commented 4 years ago

@distantcam I went back and re-read @SteveSandersonMS blog post. It's here, I missed it too, Chromium-based Edge is required on Windows.

image

VictorioBerra commented 4 years ago

So it sounds like the chromium-based edge is not installed by default yet? I assumed that edge was chromium-based from it's inception? We might have to see about fast tracking the fallback feature if 95% of Windows boxes don't have it.

ghost commented 4 years ago

I just published my Blazor Budget app using WebWidow.

Thank you @SteveSandersonMS for writing this product! If you read my below readme, you'll notice what I had to do to get the 3rd Party NuGet package JavaScript files to load when the app is running in Visual Studio. The hack is not required when running from the publish directory. No biggie.

https://github.com/Oceanware/BlazorBudgetWebWindow

image

mika76 commented 4 years ago

Sorry to write on a closed issue, but I'm trying this on a mac, targeting the new nuget package 0.1.0-20191119.2, and I'm getting the same error "System.DllNotFoundException: Unable to load shared library 'WebWindow.Native' or one of its dependencies." - anyone have any ideas? I'm assuming I don't have to install MS Edge Chromium on mac?

Edit: Some more info - all I did was as the blog post stated: new .net core 3 app, add reference, add code to program.main

 webview dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100
 Commit:    04339c3a26

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/3.0.100/
alejofv commented 4 years ago

@mika76 I'm not entirely familiar with the way nuget resolves dependencies and stuff, but I was getting the same error (also on Mac) and could narrow it down to not having the correct runtime folder under bin (I was getting win-x64 instead of a osx-x64). I managed to solve that by manually building the WebWindows repo and copying the osx-x64/native/WebWindow.Native.dylib file under my bin folder (and also updating the .deps.json file)

mika76 commented 4 years ago

@alexphi yeah I just cloned and built the whole repo, and the only project which runs straight after a build is the HelloWorldApp in testassets, the other's just don't get the .dylib file (although they do get the WebWindow.dll file) - seems copying it over manually makes them work...

distantcam commented 4 years ago

So package 0.1.0-20191118.2 has all three runtimes in the nupkg, but 0.1.0-20191119.2 only has win-x64. Downgrading to 0.1.0-20191118.2 on mac worked.

SteveSandersonMS commented 4 years ago

@distantcam @mika76 Thanks for spotting this, and sorry for the inconvenience!

This is fixed now - please try updating to the latest build 0.1.0-20191120.3. The build now correctly inserts the native assets for all platforms.

benc-uk commented 4 years ago

I have the same error on Windows 10

System.DllNotFoundException: Unable to load DLL 'WebWindow.Native' or one of its dependencies I have Edge Chrome Beta and Dev installed and I'm using 0.1.0-20191120.6 I'm on Windows 10 2004 (Insider fast ring build 19033.1) and using .NET Core 3.0.1

Running my app under WSL2 works fine (with XWinrc) but never works on Windows 10

(BTW I don't have Visual Studio installed, just VS Code)

Also tried a publish I'm seeing the WebWindow.dll and WebWindow.Native.dll in my publish folder but the exe won't run (same error) image

sondreb commented 4 years ago

Same problem here on multiple machines, my main dev machine it runs fine on. It even fails on a machine with Visual Studio Code and running from source code. Only latest version of the library: 0.1.0-20191120.6

Installing "Build Tools for Visual Studio 2019 (version 16.4)" on the machines helped and it works fine. Installed the "MSVC v142 - VS2019 C++ x64/x86 build tools (v14.23)" which is mentioned by @Code-DJ

This must be fixed, perhaps the published package changed from release to debug again?

WebView: 0.1.0-20191120.6 .NET Core 3.1 Visual Studio 2019 16.4