I've written an application that utilizes WebView2 in a Winform. It displays a local HTML file on a form. The debug version runs fine from within Visual Studio 2022. The Release version runs correctly when executed from File Explorer.
I created an installer to load the application on a separate machine. In testing the installation process, I found that the HTML page is not rendered in the installed version.
The HTML page source is downloaded to my machine from a web page. I know this is happening because I can see it in File Explorer. However, the WebView2 control on the form never renders the HTML source.
The WebView2 runtime is installed at
C:\Program Files (x86)\Microsoft\EdgeWebView\Application\109.0.1518.78
The code I use for rendering is:
string path = Path.Combine(_tempFolder, servicehtml);
try
{
webView.CreationProperties = new
Microsoft.Web.WebView2.WinForms.CoreWebView2CreationProperties();
webView.CreationProperties.BrowserExecutableFolder =
Properties.Resources.webview2_runtime_folder;
webView.Source = new Uri(path);
}
catch (Exception excp)
{
MessageBox.Show(excp.Message);
WriteLog(LogType.Info, Properties.Resources.ERR_WEBVIEW2_FAILURE, new object[]
{excp.Message });
}
I set the BrowserExecutableFolder according to the discussion in Details about the Fixed Version runtime distribution mode
What am I missing that prevents the HTML from rendering correctly?
UPDATE:
I changed the above code to:
webView.CreationProperties = new Microsoft.Web.WebView2.WinForms.CoreWebView2CreationProperties();
webView.CreationProperties.BrowserExecutableFolder =
Properties.Resources.webview2_runtime_folder;
webView.CreationProperties.UserDataFolder = _tempFolder; //<=====
webView.Source = new Uri(path);
Adding the UserDataFolder allowed me to change where my HTML file was located.
Note: The WebView2 runtime will create an "EBWebView" subfolder at the UserDataFolder path.
Related
I'm coding a program that extract text from image using Tesseract .. The program should bring all images from a directory and put them one by one in a picture box and then extract the text from them. I have downloaded an English trained data from this link and put it inside Debug folder https://github.com/tesseract-ocr/tessdata/blob/master/eng.traineddata
The exception is:
Here's my code: Exception has been thrown by the target of an invocation.
and the inner exception indicated in catch was : Failed to find library "liblept172.dll" for platform x86.
private void button1_Click(object sender, EventArgs e)
{
Image image;
string[] images = Directory.GetFiles("E:\\Omar Project\\New", "*.png");
for (int i = 0; i < images.Length;i++)
{
image = Image.FromFile(images[i]);
pictureBox1.Image = image;
//ocr = new TesseractEngine(#"tessdata", "eng", EngineMode.Default);
using (var engine = new TesseractEngine("E:\\Omar Project\\Extracting Text From Image Using Microsoft Office\\Extracting Text From Image Using Microsoft Office\\bin\\Debug\\eng.traineddata", "eng", EngineMode.Default))
{
using(var img=Pix.LoadFromFile(images[i]))
{
using(var page=engine.Process(img))
{
richTextBox1.Text += page.GetText();
}
}
}
}
}
Create a folder "x64" or "x86" in your project directory (where your .csproj file is located) and copy liblept1760.so and libtesseract400.so into it. Now you should be able to see your both files in visual studio. You will have to set "copy to output directory" (is the property called like this in english?) for both files to "always"
Make sure you have the following packages installed inside your container
apt-get install -y libgif7 libjpeg62 libopenjp2-7 libpng16-16 libtiff5 libwebp6
Otherwise the dlopen command for liblept will fail and you will get your mentioned errormessage.
If you don't have the liblept package installed inside your container and only copied the .so file into the x64 directory, the open command for libtesseract will fail.
To fix this, you have to create a sym link to your liblept shared object.
Just run inside your container / Dockerfile
ln -s /app/x64/liblept1760.so /usr/lib/x86_64-linux-gnu/liblept.so.5
Make sure to use the correct source path. For default asp.net core docker images and my described way /app/x64/liblept1760.so should be working.
Wiki Tesseract
Common reasons for failure are:
The Visual Studio 2015 x86 & x64 Runtime is not installed, as detailed on the main readme page these can be found here.
The x86 and x64 versions leptonica (liblept172.dll) and tesseract (libtesseract304.dll) were not copied to their respective folders in the bin directory.
DotNet may be reporting the wrong architecture, for instance a known issue is that for an Application compiled using the prefer 32-bit flag will report it's running on x64 when running on windows 64-bit OS (see issue #55). A common workaround is to either change the cpu architecture to x86.
Your running this on an unsupported architecture (e.g. ARM).
Further diagnosis
Tesseract will write the detected architectures and paths searched to the System.Diagnostics source named "Tesseract" which will be helpful for figuring out what is going on. An example configuration is provided at the end of the page.
If the correct version of the library is being found but fails to load, the log will tell you if this is the case, then the next step is to enable logging of binding errors and check the fusion log. Note that it's been my experience that Windows may log these errors to the Windows Event Log so it might be worth checking that first. Further details can be found here:
https://blogs.msdn.microsoft.com/suzcook/2003/05/29/debugging-assembly-loading-failures/
http://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net
If you cannot resolve the issue please file a new issue including the library version, operating system your executing the code on, the target architecture for the entry program, and a copy of the full standard and trace outputs. Note you'll need to enable System.Diagnostics output for the Tesseract source as previously mentioned.
I can not believe I have to ask this, but here I am!
Here is all I have done:
Visual Studio 2013 - Create New ASP.NET Web Application (Empty).
Saved it as MyWebApp.
Once the project was created, I right-clicked and added a new item: Web Form
Saved it as index.aspx
In the designer, added a button.
Created a Click event for this button that looks like:
protected void Button1_Click(object sender, EventArgs e)
{
string myStringVariable = "foo";
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
}
Done. That's it. Can't get any simpler.
So then I built it. And published it using Visual Studio 2013. I chose the Publish method of File System and a local location of C:\inetpub\wwwroot.
Now, I did this locally, in my VM, just to see what files it would place. And as I thought, in wwwroot:
It created a bin folder and placed MyWebApp.dll in this folder.
It placed a web.config
It placed index.aspx.
So, now, let's go to my actual real web server! I mean, I can place static html files there right now, and view them from my browser. It works!
So I go to the default website (c:\inetpub\wwwroot), created a folder called ASP, and placed those files in it (index.aspx, web.config, bin folder with dll).
When I run it using (I'm on the server): http://localhost/ASP/index.aspx I continually get this parser error:
Parser Error Description: An error occurred during the parsing of a
resource required to service this request. Please review the following
specific parse error details and modify your source file
appropriately.
Parser Error Message: The file '/ASP/index.aspx.cs' does not exist.
Source Error:
Line 1: <%# Page Language="C#" AutoEventWireup="true"
CodeFile="index.aspx.cs" Inherits="MyWebApp.index" %> Line 2: Line
3:
Source File: /ASP/index.aspx Line: 1
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.6.1086.0
(I have switched between CodeFile and CodeBehind - based on some googling here, neither works).
No matter what I do, I can't get index.aspx to "find/see" index.aspx.cs that's inside the dll. Is there some configuration step I'm missing? I just don't get it.
Thanks.
EDIT: To be clear, I believe it's because I put it in a subfolder. It seems to work if I put those same files just in wwwroot, instead of the subfolder. I just added that to the title, because as soon as I pressed submit on this question - I realized, maybe it's because it's in this subfolder! Isn't that the way this always works? Ask for help, and the process of writing it up gives you clarity? :)
EDIT: Arrgh! The other tid-bit of info I left out was that I was trying this on Port 81. I had created a 2nd Site (IIS) and binded it to port 81 (and yes I'm including that in my URL). And I was playing around there. And I had even thought to make it an Application (the subfolder). But it just doesn't work there. Only under my Default Web Site. I must be missing some type of configuration information.
I compiled the cefsharp and did a setup file from it. I installed the my custom browser on my windows 7 64 bit pc and I made my custom browser, the default browser. There is not problem until here. It runs perfectly when I run the browser.exe.
Problem is:
When I clicked a local html file or a link like that this picture(), The browser.exe run but cannot open, returns error. Error is "It cannot load cefsharp.dll, cefshap.core.dll ..., all cefsharp dlls"
How can I solve this?
Cefsharp has a bug in Cefsharp.dll while loading the dependencies. I fixed it and error gone.
While loading the dependencies some paths are absoulate. I change them into relative paths.
I am using "GeckoFx-29.0-0.6" for having a firefox web browser control in Windows Form application.
When I run my Windows form application which have GeckoFX browser control everyting is working fine.
I use the following code in my application,
Gecko.Xpcom.Initialize("xulrunner/");
and I use xcopy to load the bin folder with xulrunner folder. So in this scenario the xul runner is loaded from the same loaction where the application .exe is found.
When I make wix setup of my application, I am doing the same process, I have xulrunner folder in the same location as application .exe. But the application is not able to invoke the windows form. Its showing the message "unable to load DLL 'xul'".
I resolved this issue by changing my setup such that the xulrunner folder is copied to the c:/windows/system32 folder location. When I do so, the application works successfully in some machines but do not work in someother.
Is there any way to resolve this? such that I don't need to put the xulrunner in the system32 folder ?
You can try giving the full path to the xulrunner directory. Do something like:
var programDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
Gecko.XpCom.Initialize(Path.Combine(programDirectory, "xulrunner");
That will work when the app is installed, and if you've placed xulrunner in your output directory. If you don't want to bother copying it in there, then you will want to make the above code a bit smarter so that when you're just running from Visual Studio, it can locate xulrunner where you have placed it.
Our class for smartly finding files under a number of conditions, FileLocator, is open source, you can grab it and use it.
I have wasted lot of time trying to fix the issue and found that the error was due to mismatch of geckofix and xulruneer version. they both should be same. checkout this link to understand more https://bitbucket.org/geckofx/geckofx/wiki/Version_lists
Heads up, I know this post is old, but I discovered something. If you use Visual Studio (2019 is the version I have, at the time of this post), and you added the Geckofx45.64 via NuGet, there is also a Geckofx45.64.Windows package. When you read the description of this package from Visual Studio NuGet Manager, it says:
This should only be used for building Geckofx... Do NOT use this
package if you just want to include Geckofx in your application.
Well, I downloaded it anyway, and checked the contents of this package and noticed that it had all the files that Geckofx.45 was complaining about missing during run-time (init). I, therefore, added the package, and Geckofx now works exactly the way it instructs.
library that allows embedding gecko in C# applications.
Example Usage:
[STAThread]
static void Main(string[] args)
{
Xpcom.Initialize("Firefox64");
var geckoWebBrowser = new GeckoWebBrowser {Dock = DockStyle.Fill};
Form f = new Form();
f.Controls.Add(geckoWebBrowser);
geckoWebBrowser.Navigate("www.google.com");
Application.Run(f);
}
Hope this helps. This one had me going in circles for a while.
You'll get that error when you forget to run the line Xpcom.Initialize("Firefox64"); before using GeckoWebBrowser.
This also works
Gecko.Xpcom.Initialize(Environment.CurrentDirectory + "\\xulrunner");
I have a WPF/C# application. It has a button that runs a particular PowerPoint presentation in slide show mode using the following code:
public bool OpenHelpFile()
{
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = "powerpnt.exe";
// the /S option starts PowerPoint in slide show mode
processStartInfo.Arguments = "/S \"Resources\\Midas 3.pptx\"";
try { Process.Start(processStartInfo); }
catch { return false; }
return true;
}
This works perfectly when I'm debugging in Visual Studio (2010), or even when running (not debugging) using the 'Release' solution configuration. However, after publishing the application using ClickOnce, the button no longer opens the presentation. Instead, I get this warning:
The presentation file is in a folder in the solution named 'Resources' and in its properties window, it has a Build Action of None and the Copy To Output Directory property is set to Copy Always. I believe that these settings could be the problem, but I'm not sure which options to use. Setting the Build Action to Resource didn't help because that embeds the file into an assembly from which PowerPoint cannot access the file.
I have also searched the hidden AppData folder where ClickOnce applications are installed and could not find the presentation file there. The problem could also lie with ClickOnce. If anyone can shed some light on this problem, I would greatly appreciate it.
Many thanks in advance.
UPDATE>>>
I found a solution after reading the page that #Osama Javed's second link pointed to... ignore the first link.
As it turned out, all I needed to do was to change the Build Action of the file to Content. This adds the file into the Application Files window (found in the Publish tab of the Project Properties page) where it could be included in the list of deployment files.