试图发送HTTP请求时奇怪的例外
我在尝试通过执行HTTP请求来获取网站内容的同时获得此例外。 我尝试了几个不同的URL(包括粘贴),并且我得到了一个奇怪的例外,这些例外是我从未得到过的:
private static string GetWebsiteContent()
{
try
{
var webClient = new WebClient();
webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0");
Console.WriteLine(webClient.DownloadString("https://pastebin.com/MyUrl"));
return null;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return null;
}
这是我所说的方法,我不需要任何形式的解释,只是对网站的简单请求。
例外:
System.Configuration.ConfigurationErrorsException: Impossibile inizializzare il sistema di configurazione ---> System.Configuration.ConfigurationErrorsException: Errore durante il cari
camento di un file di configurazione: L'inizializzatore di tipo di 'System.MarvinHash' ha generato un'eccezione. (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config)
---> System.TypeInitializationException: L'inizializzatore di tipo di 'System.MarvinHash' ha generato un'eccezione. ---> System.NullReferenceException: Riferimento a un oggetto non im
postato su un'istanza di oggetto.
in System.Collections.HashHelpers.GetEntropy()
in System.OrdinalComparer.System.IWellKnownStringEqualityComparer.GetRandomizedEqualityComparer()
in System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
in System.Security.Cryptography.CryptoConfig.get_DefaultNameHT()
in System.Security.Cryptography.CryptoConfig.CreateFromName(String name, Object[] args)
in System.Security.Cryptography.RandomNumberGenerator.Create()
in System.MarvinHash.GenerateSeed()
in System.MarvinHash..cctor()
--- Fine della traccia dello stack dell'eccezione interna ---
in System.Xml.NameTable..ctor()
in System.Configuration.XmlUtil..ctor(Stream stream, String name, Boolean readToFirstElement, ConfigurationSchemaErrors schemaErrors)
in System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
--- Fine della traccia dello stack dell'eccezione interna ---
in System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
in System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
in System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- Fine della traccia dello stack dell'eccezione interna ---
in System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
in System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
in System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
in System.Configuration.ConfigurationManager.GetSection(String sectionName)
in System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
in System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
in System.Diagnostics.DiagnosticsConfiguration.Initialize()
in System.Diagnostics.DiagnosticsConfiguration.get_Sources()
in System.Diagnostics.TraceSource.Initialize()
in System.Net.Logging.InitializeLogging()
in System.Net.Logging.get_On()
in System.Net.WebClient.DownloadString(Uri address)
in SchoolProject.WebUtils.GetWebsiteContent() in C:\Users\Admin\Desktop\Projects\CS\SchoolProject\WebUtils.cs:riga 25
Process finished with exit code -1,073,741,510.
IM在不同的计算机上尝试了以下代码,但结果仍然相同。
我正在使用.NET 4.0(必须)
有人知道为什么会发生这种情况以及如何解决此问题?
Im getting this exception while trying to get a website content by doing an HTTP request.
I tryed with several different urls (including PasteBin) and im getting a weird exception which i never got before:
private static string GetWebsiteContent()
{
try
{
var webClient = new WebClient();
webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0");
Console.WriteLine(webClient.DownloadString("https://pastebin.com/MyUrl"));
return null;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
return null;
}
Thats the method that i call, i dont it need any kind of explanation, just a simple request to a site.
The exception:
System.Configuration.ConfigurationErrorsException: Impossibile inizializzare il sistema di configurazione ---> System.Configuration.ConfigurationErrorsException: Errore durante il cari
camento di un file di configurazione: L'inizializzatore di tipo di 'System.MarvinHash' ha generato un'eccezione. (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config)
---> System.TypeInitializationException: L'inizializzatore di tipo di 'System.MarvinHash' ha generato un'eccezione. ---> System.NullReferenceException: Riferimento a un oggetto non im
postato su un'istanza di oggetto.
in System.Collections.HashHelpers.GetEntropy()
in System.OrdinalComparer.System.IWellKnownStringEqualityComparer.GetRandomizedEqualityComparer()
in System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
in System.Security.Cryptography.CryptoConfig.get_DefaultNameHT()
in System.Security.Cryptography.CryptoConfig.CreateFromName(String name, Object[] args)
in System.Security.Cryptography.RandomNumberGenerator.Create()
in System.MarvinHash.GenerateSeed()
in System.MarvinHash..cctor()
--- Fine della traccia dello stack dell'eccezione interna ---
in System.Xml.NameTable..ctor()
in System.Configuration.XmlUtil..ctor(Stream stream, String name, Boolean readToFirstElement, ConfigurationSchemaErrors schemaErrors)
in System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
--- Fine della traccia dello stack dell'eccezione interna ---
in System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
in System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
in System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- Fine della traccia dello stack dell'eccezione interna ---
in System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
in System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
in System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
in System.Configuration.ConfigurationManager.GetSection(String sectionName)
in System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
in System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
in System.Diagnostics.DiagnosticsConfiguration.Initialize()
in System.Diagnostics.DiagnosticsConfiguration.get_Sources()
in System.Diagnostics.TraceSource.Initialize()
in System.Net.Logging.InitializeLogging()
in System.Net.Logging.get_On()
in System.Net.WebClient.DownloadString(Uri address)
in SchoolProject.WebUtils.GetWebsiteContent() in C:\Users\Admin\Desktop\Projects\CS\SchoolProject\WebUtils.cs:riga 25
Process finished with exit code -1,073,741,510.
Im tryed the following code on different computers, but the result still the same.
Im using .NET 4.0 (must)
Does anyone know why this happens and how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不再建议使用
WebClient
。最好使用httpclient
而不是It is no longer recommended to use
WebClient
. And it is better to useHttpClient
instead