4

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 enter image description here

Pic.2 enter image description here

Pic.3 enter image description here

Pic.4 enter image description here

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
enter image description here

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"?

eusataf
  • 807
  • 1
  • 12
  • 24
  • 2
    Even though System.Text.Encoding.CodePages is included as a NuGet package it doesn't appear to be referenced/included by the project. Try adding a reference to the project references – phuzi Jan 15 '19 at 11:37
  • @phuzi `Try adding a reference to the project references` - how to do it. I can not understand. Could you describe in more detail how to do this? – eusataf Jan 15 '19 at 11:39
  • 1
    Maybe this will help: https://stackoverflow.com/a/40775352/592958 – phuzi Jan 15 '19 at 12:13
  • @phuzi updated question – eusataf Jan 15 '19 at 13:33
  • @phuzi `updated-2` question – eusataf Jan 15 '19 at 13:46
  • 2
    I just created a new console application, installed the AngleSharp package (0.10.1) and copy/pasted the "First Steps" code from [this page](https://github.com/AngleSharp/AngleSharp/wiki/Documentation). I got the same exception as you, so I installed the `System.Text.Encoding.CodePages` package and the application built and ran with no issues. You said you installed that last package in your project, but can you see it in your project references? – Reinstate Monica Cellio Jan 15 '19 at 14:04
  • @Archer Updated the question. `Update-3` Did I understand you correctly? – eusataf Jan 15 '19 at 14:18
  • Yes - that's fine and should work. I can't read anything other than the code, I'm afraid, so I can't be much help if it still doesn't work. – Reinstate Monica Cellio Jan 15 '19 at 14:21
  • @Archer I understood you. I understood you correctly, because the text in the picture is not in English, then you have no opportunity to help? Or did you mean something else? – eusataf Jan 15 '19 at 14:27
  • Yes, that's what I mean. Also, it's difficult to help because we appear to have done the same thing and it works for me but not for you. (By the way, HTH means "Hope that helps") – Reinstate Monica Cellio Jan 15 '19 at 14:56
  • @Archer I thought... Maybe you will not be difficult, the project that works for you, put on file sharing. I will try to open it at home. – eusataf Jan 15 '19 at 15:07
  • Sorry, but I can't do that. Here are the steps. 1) Create a new console application (.Net 4.6.1). Copy and paste the code from `Main()` in "First Steps" example on [this linked page](https://github.com/AngleSharp/AngleSharp/wiki/Documentation). Open Nuget Package Manager and add the package AngleSharp (v0.10.1), then add the package System.Text.Encoding.CodePages (v4.5.1). That's it - it should build and run. – Reinstate Monica Cellio Jan 15 '19 at 15:30
  • @Archer Does not work. The project attached to the question just in case. (`Update-4` ) Probably while they will work with AngleSharp - 9. – eusataf Jan 15 '19 at 16:09
  • I can't help you then. I can only think you have an environment issue (problem with your Visual Studio or .Net installation). Good luck resolving your issue. – Reinstate Monica Cellio Jan 15 '19 at 16:19

2 Answers2

5

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.

bh_earth0
  • 2,537
  • 22
  • 24
3

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.

RJB
  • 2,063
  • 5
  • 29
  • 34