HtmlParser. Failed to load file or assembly - c#

Bug Report
System.TypeInitializationException
HResult = 0x80131534
Message = Initializer type "AngleSharp.Configuration" threw an exception.
Source = AngleSharp
Stack trace:
in AngleSharp.Configuration.get_Default ()
in AngleSharp.BrowsingContext.NewFrom [TService] (TService instance)
in AngleSharp.Html.Parser.HtmlParser..ctor ()
in rsh.Parser_test..ctor () in Z: \ vs \ csharp \ prb \ rsh \ rsh \ Parser_test.cs: line 19
in rsh.Form1..ctor () in Z: \ vs \ csharp \ prb \ rsh \ rsh \ Form1.cs: line 18
in rsh.Program.Main () in Z: \ vs \ csharp \ prb \ rsh \ rsh \ Program.cs: line 19
Internal exception 1:
FileNotFoundException: Failed to load file or assembly
"System.Text.Encoding.CodePages, Version = 4.0.2.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" or one of their dependencies. Cannot find the specified file.
Can you reproduce the problem in a MWE?
no
Are you running the latest version of AngleSharp?
Version - 0.10.1
Did you check the FAQs to see if that helps you?
used google search. did not help
Are you reporting to the correct repository? (there are multiple AngleSharp libraries, e.g., AngleSharp.Css for CSS support)
see screen
Did you perform a search in the issues?
Searched for phrase: "Failed to load file or assembly"
Description
I get the error "Failed to load file or assembly" during application launch
Steps to Reproduce
Error occurs when starting the application
Environment details: [OS, .NET Runtime, ...]
Win 7x64.
VS - 2017
.NET Framework 4.6.1
Code
using AngleSharp.Html.Parser;
namespace rsh
{
class Parser_test
{
HtmlParser domParser;
public Parser_test()
{
domParser = new HtmlParser();
}
}
}
I installed:
"System.Text.Encoding.CodePages".
Error remained.
Additional reasoning - link
Pic.1
Pic.2
Pic.3
Pic.4
Update-1
Based on - stackoverflow.com/a/40775352/10530657
Completed
Update-Package -reinstall.
Closed, opened Visual Studio.
Opened in Visual Studio 2015.
No result.
Update-2
Installed "AngleSharp - 0.9.11".
The error is gone.
Update-3
Installed - System.Text.Encoding.CodePages
Pic.5
Update-4
Collected the console project,
The project gives an error.
Maybe someone will have the opportunity to check on their side.
Or send me a project that works.
Maybe this will help identify the cause of the error.
The project is made on the basis of documentation "AngleSharp"- documentation . link
Link to the project - link
Question
How to make the error not appear in "AngleSharp - 0.10.01"?

i had the same problem
your project > rightClick > manage nuget packages >
search : System.Text.Encoding.CodePages
install that .
long:
anglesharp nuget details:
.net framework 4.6 requires "System.Text.Encoding.CodePages".
just installing angleSharp, doesn't install the required package automatically. you need to install from nuget package manager.

I had the same exception, and it took me a few minutes to realize....
If you have AngleSharp in a class library, you also need to install it in whatever is consuming the class library.
Oops.

Related

Problem to build VS-project with DCOM-refs under GitHub Actions

One of the C# projects in my solution has references to 2 DCOM apps (win32, quite an old DCOM apps).
To successfully build my VS project on PC it is enough to copy 2 exe files and run 2 commands:
XObjectsEx.exe -regserver
SfGbVars.exe -regserver
And then I can run a command to build it:
msbuild SfR2.sln -p:Configuration=Release
Build is successful.
Thus, to successfully build my solution it is enough to do only these steps:
take a new clean PC install (for example: clean VM install with Windows 10/2012/2019 - just any, I tried all of these)
install MS Build Tools 2019
copy 2 exe files + run 2 mentioned commands
run mentioned build command
But(!)...
When I try to do the same under GitHub Actions it reports errors like these:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2827,5): warning MSB3284: Cannot get the file path for type library "d6ed8d7e-1780-4747-b41b-a685526cb19b" version 1.0. Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)) [D:\a\spectrum-abz-scm-sw-cust\spectrum-abz-scm-sw-cust\Modules\SfManagement\SfR2\assemblies\Sf.OleOp\source\Sf.OleOp.csproj]
CoreCompile:
[...]
D:\a\spectrum-abz-scm-sw-cust\spectrum-abz-scm-sw-cust\Modules\SfManagement\SfR2\assemblies\Sf.OleOp\source\OprGbVar.cs(23,7): error CS0246: The type or namespace name 'SFGlobalVars' could not be found (are you missing a using directive or an assembly reference?) [D:\a\spectrum-abz-scm-sw-cust\spectrum-abz-scm-sw-cust\Modules\SfManagement\SfR2\assemblies\Sf.OleOp\source\Sf.OleOp.csproj]
D:\a\spectrum-abz-scm-sw-cust\spectrum-abz-scm-sw-cust\Modules\SfManagement\SfR2\assemblies\Sf.OleOp\source\OprGbVar.cs(744,17): error CS0246: The type or namespace name 'SFGlobalVars' could not be found (are you missing a using directive or an assembly reference?) [D:\a\spectrum-abz-scm-sw-cust\spectrum-abz-scm-sw-cust\Modules\SfManagement\SfR2\assemblies\Sf.OleOp\source\Sf.OleOp.csproj]
CompilerServer: server - server processed compilation - 93f84f1f-193a-4dcc-9b12-98452dca1411
In attempt to resolve this problem I added a step to YML file (a step before calling the build itself):
- name: Restore artifacts (SF)
run: build-tools\scripts\InstallArtifacts.ps1 ${{ env.RepoRoot }}/${{ env.OpcPackages_Path }}
working-directory: ${{ env.RepoRoot }}
Where InstallArtifacts.ps1 script executing also following commands:
XObjectsEx.exe -regserver
SfGbVars.exe -regserver
rem ===== .NET registration =====
set NetHome=C:\Windows\Microsoft.NET\Framework\v4.0.30319
set SdkHome=C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools
"%SdkHome%\TlbImp.exe" SfGbVars.exe /out:SfGbVars_Net.dll
"%SdkHome%\TlbImp.exe" XObjectsEx.exe /out:XObjectsEx_Net.dll
"%NetHome%\RegAsm.exe" SfGbVars_Net.dll
"%NetHome%\RegAsm.exe" XObjectsEx_Net.dll
In GitHub Actions output I clearly see that all these commands were correctly executed. In output it writes "Types registered successfully" and so on.
Also I checked generated SfGbVars_Net.dll and XObjectsEx_Net.dll with Reflector and confirms - there is a valid .NET wrappers for these DCOM objects.
However that does not affect the build result. It is still reporting the same errors! :-\
Could you please advise - how to resolve this problem?
Why there is such a strange difference in behavior between normal PC and virtual PC under GitHub Actions? So, on PC it is enough to run {app} -regserver command but under GitHub Actions that does not work.
Note:
here example of my YML file - https://drive.google.com/file/d/1Id-sMWT7BrGj-TBGvmVEpPIVe_kH9IJq/view?usp=share_link

I'm not able to build my unity project into apk

I'm not able to build my unity project into apk, whenever i try to build it throw errors
I'm using unity 2020.3.21
I'm using api level 31 because i want to submit the update of my game on playstore and now they changed the api level to 31.
errors
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':unityLibrary:GoogleMobileAdsPlugin.androidlib:compileReleaseAidl'.
> Installed Build Tools revision 33.0.0 is corrupted. Remove and install again using the SDK Manager.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with -
The other error
Could not determine the dependencies of task ':unityLibrary:GoogleMobileAdsPlugin.androidlib:compileReleaseAidl'.
> Installed Build Tools revision 33.0.0 is corrupted. Remove and install again using the SDK Manager.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 17s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
]
As i can see in the error it is mentioned that Build Tools revision 33.0.0 is corrupted i already renistalled using the android studio but still the same error or maybe i did it wrong. if you know anything about this error then you are welcome any help should be appericiated.
try to install via unity package manager instead of android studio since it may have different file names for the different applications
hope this helps!

DinkToPdf Net Core not able to load DLL files

I am trying to generate PDFs from HTML SQL server database using DinkToPdf library.
In the startup file I have added:
var context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll"));
The line gives me this error on launching the web app:
DllNotFoundException: Unable to load DLL 'C:\Program Files\IIS Express\libwkhtmltox.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
System.Runtime.Loader.AssemblyLoadContext.InternalLoadUnmanagedDllFromPath(string unmanagedDllPath)
DllNotFoundException: Unable to load DLL 'C:\Program Files\IIS Express\libwkhtmltox.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Just in case anyone else is having the same issue I was able to solve it by installing Microsoft Visual C++ 2015 Redistributable.
It is mentioned in library's git repo that you should download binaries and include them in your source code:
Copy native library to root folder of your project. From there .NET Core loads native library when native method is called with P/Invoke. You can find latest version of native library here. Select appropriate library for your OS and platform (64 or 32 bit).
What was breaking things was that I was going to that url and right click on each file and select save link as(chrome). This leads to a broken file being downloaded:
DON'T DO THAT
you have to open each file within github and then use that Download button.
The healthy file is much bigger than what you would get if you go the wrong way!
ridiculous but the problem may be caused by this ...
On Asp.Net Core application I use it like this to get the current directory on runtime
#if DEBUG
//windows
string filePath = $#"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\libwkhtmltox.dll";
#else
//linux
string filePath = #$"{(($#"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}/libwkhtmltox.so").Replace(#"\", #"/"))}";
#endif
CustomAssemblyLoadContext context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary(filePath);
serviceCollection.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
#endregion
I found some work-arounds. They are not perfect but worth a try, and they did do help and I was able to generate PDFs from SQl Server. I put the .dll files in the following folder and it worked.
C:\Program Files\IIS Express
and the loaded the .dll files with
Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll");
The other way I went for the whole Path
context.LoadUnmanagedLibrary(Path.GetFullPath(#"C:\Users\User\source\repos\WebSolution\WebApp\libwkhtmltox.dll"));
Both of them worked. However, I urge Net Core developers to work on the GetCurrentDir very well. Or a Method to load from the Project or Solution Folder
Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll");
if you are using asp.net core on Linux then you need to install required packages by using following command
apt-get update \
&& apt-get install -y --no-install-recommends \
zlib1g \
fontconfig \
libfreetype6 \
libx11-6 \
libxext6 \
libxrender1 \
&& curl -o /usr/lib/libwkhtmltox.so \
--location \
https://github.com/rdvojmoc/DinkToPdf/raw/v1.0.8/v0.12.4/64%20bit/libwkhtmltox.so

How to compile c# in Microsoft's new Visual Studio Code?

I have installed the preview version of Microsoft's new code editor "Visual Studio Code". It seems quite a nice tool!
The introduction mentions you can program c# with it, but the setup document does not mention how to actually compile c# files.
You can define "mono" as a type in the "launch.json" file, but that does not do anything yet. Pressing F5 results in: "make sure to select a configuration from the launch dropdown"...
Also, intellisense is not working for c#? How do you set the path to any included frameworks?
Launch.json:
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Cars.exe",
// Type of configuration. Possible values: "node", "mono".
"type": "mono",
// Workspace relative or absolute path to the program.
"program": "cars.exe",
},
{
"type": "mono",
}
Since no one else said it, the short-cut to compile (build) a C# app in Visual Studio Code (VSCode) is SHIFT+CTRL+B.
If you want to see the build errors (because they don't pop-up by default), the shortcut is SHIFT+CTRL+M.
(I know this question was asking for more than just the build shortcut. But I wanted to answer the question in the title, which wasn't directly answered by other answers/comments.)
Intellisense does work for C# 6, and it's great.
For running console apps you should set up some additional tools:
ASP.NET 5; in Powershell: &{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}
Node.js including package manager npm.
The rest of required tools including Yeoman yo: npm install -g yo grunt-cli generator-aspnet bower
You should also invoke .NET Version Manager: c:\Users\Username\.dnx\bin\dnvm.cmd upgrade -u
Then you can use yo as wizard for Console Application: yo aspnet Choose name and project type. After that go to created folder cd ./MyNewConsoleApp/ and run dnu restore
To execute your program just type >run in Command Palette (Ctrl+Shift+P), or execute dnx . run in shell from the directory of your project.
SHIFT+CTRL+B should work
However sometimes an issue can happen in a locked down non-adminstrator evironment:
If you open an existing C# application from the folder you should have a .sln (solution file) etc..
Commonly you can get these message in VS Code
Downloading package 'OmniSharp (.NET 4.6 / x64)' (19343 KB) .................... Done!
Downloading package '.NET Core Debugger (Windows / x64)' (39827 KB) .................... Done!
Installing package 'OmniSharp (.NET 4.6 / x64)'
Installing package '.NET Core Debugger (Windows / x64)'
Finished
Failed to spawn 'dotnet --info' //this is a possible issue
To which then you will be asked to install .NET CLI tools
If impossible to get SDK installed with no admin privilege - then use other solution.
Install the extension "Code Runner". Check if you can compile your program with csc (ex.: csc hello.cs). The command csc is shipped with Mono. Then add this to your VS Code user settings:
"code-runner.executorMap": {
"csharp": "echo '# calling mono\n' && cd $dir && csc /nologo $fileName && mono $dir$fileNameWithoutExt.exe",
// "csharp": "echo '# calling dotnet run\n' && dotnet run"
}
Open your C# file and use the execution key of Code Runner.
Edit: also added dotnet run, so you can choose how you want to execute your program: with Mono, or with dotnet. If you choose dotnet, then first create the project (dotnet new console, dotnet restore).
To Run a C# Project in VS Code Terminal
Install CodeRunner Extension in your VS Code (Extension ID: formulahendry.code-runner)
Go to Settings and open settings.json
Type in code-runner.executorMap
Find "csharp": "scriptcs"
Replace it with this "csharp": "cd $dir && dotnet run $fileName"
Your project should Run in VS Code Terminal once you press the run button or ALT + Shift + N

Does Coverity support xbuild (mono)?

I've a C# project: https://github.com/Pro/dkim-exchange
It uses Travis CI: https://travis-ci.org/Pro/dkim-exchange
Travis successfully builds my project.
I wanted to set up Coverity to do automatic code quality measurements. For this I configured my .travis.yml as follows:
language: objective-c
env:
global:
- EnableNuGetPackageRestore=true
# The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
# via the "travis encrypt" command using the project repo's public key
- secure: "kC7O0CWm9h4g+tzCwhIZEGwcdiLrb1/1PijeOKGbIWGuWS7cIksAkj2tRNMgtxxcE9CFQr8W7xDv2YzflCIlqN1nGkFjbyD4CrNg6+V1j0fZjPOQ6ssdBBVPrfrvecsAUJ0/48Tqa9VTkEpZSlwOF/VS1sO2ob36FVyWjtxvG9s="
matrix:
- MONO_VERSION="3.10.0"
install:
# Fetch Mono
- wget "http://download.mono-project.com/archive/${MONO_VERSION}/macos-10-x86/MonoFramework-MDK-${MONO_VERSION}.macos10.xamarin.x86.pkg"
- sudo installer -pkg "MonoFramework-MDK-${MONO_VERSION}.macos10.xamarin.x86.pkg" -target /
script:
- xbuild travis.proj
addons:
coverity_scan:
project:
name: "Pro/dkim-exchange"
description: "Build submitted via Travis CI"
notification_email: mail#example.com
build_command_prepend: "xbuild /t:CleanAll travis.proj"
build_command: "xbuild /t:Build travis.proj"
branch_pattern: coverity_scan
If I execute the coverity build commands as indicated here (using msbuild): https://scan.coverity.com/download?tab=csharp the uploaded archive is analyzed correctly, but in combination with travis, the coverity analysis fails (see e.g. this build log: https://travis-ci.org/Pro/dkim-exchange/builds/42295611).
There's this warning:
[WARNING] No files were emitted. This may be due to a problem with your configuration
or because no files were actually compiled by your build command.
Please make sure you have configured the compilers actually used in the compilation.
I think this may be related to xbuild from Mono. Unfortunately Dr. Google didn't find anythin about Coverity+xbuild. Does Coverity support xbuild? If yes, how can I correctly setup the project?
When it comes to C#, Coverity actually only supports msbuild.
You can find some more official information about this in the following
http://www.coverity.com/library/pdf/CoverityStaticAnalysis.pdf
https://communities.coverity.com/message/6251#6251
The last link explicitly states
Our C# analysis only supports the Visual Studio C# compilers
So, no xbuild support as of now.
Update:
When you download the Coverity build tool, the doc/en/help/cov-build.txt explicitly states the following:
C# build capture is only supported on Windows.

Categories

Resources