我正在製作一個程序,該程序運行良好,除了我開始創建更新系統並以某種方式無法工作。啓動畫面使用webClient檢查更新,現在似乎也出現錯誤。我設置它以便啓動屏幕下載一個文本文件。如果版本不匹配,則單獨的表單將啓動並使用WebClient下載更新程序。我創建了這個表單兩次。它有1個progressBar,1個webClient,一個圖像背景和1個標籤。更新應該下載,在欄上顯示其進度,然後打開更新程序並關閉主程序。我第一次創建表單時,我運行它,它會凍結而不下載文件。在我停止調試之後,visual c#express 2010的設計窗口會崩潰,我必須重新啓動vc#。該窗口將顯示除了webClient以外我已添加的所有項目。所以我試着再次調試,我得到了這個消息:WebClient拋出「沒有數據可用於編碼1252」
Error 1 Invalid Resx file. Type in the data at line 138, position 5, cannot be loaded because it threw the following exception during construction: No data is available for encoding 1252. C:\Users\DjLyriz\documents\visual studio 2010\Projects\TubeRip\TubeRip\updates.resx TubeRip
Error 2 TargetInvocationException: Type in the data at line 138, position 5, cannot be loaded because it threw the following exception during construction: No data is available for encoding 1252.
at System.Resources.ResXResourceReader.ParseXml(XmlTextReader reader)
at System.Resources.ResXResourceReader.EnsureResData()
at System.Resources.ResXResourceReader.GetEnumerator()
at Microsoft.Build.Tasks.ProcessResourceFiles.ReadResources(ReaderInfo readerInfo, IResourceReader reader, String fileName)
at Microsoft.Build.Tasks.ProcessResourceFiles.ReadResources(String filename, Boolean shouldUseSourcePath)
at Microsoft.Build.Tasks.ProcessResourceFiles.ProcessFile(String inFile, String outFileOrDir)
XmlException: Type in the data at line 138, position 5, cannot be loaded because it threw the following exception during construction: No data is available for encoding 1252. Line 138, position 5.
NotSupportedException: No data is available for encoding 1252.
at System.Text.BaseCodePageEncoding.LoadCodePageTables()
at System.Text.BaseCodePageEncoding..ctor(Int32 codepage, Int32 dataCodePage)
at System.Text.SBCSCodePageEncoding..ctor(SerializationInfo info, StreamingContext context)
C:\Users\DjLyriz\documents\visual studio 2010\Projects\TubeRip\TubeRip\updates.resx TubeRip
所以我從窗體中刪除了webClient並重試。我第二次得到同樣的錯誤。所以我GOOGLE了第一個錯誤,並發現沒有修復hackforums一個響應。現在我完全失去了。我所有的Web客戶端似乎都在這樣做,我不知道爲什麼。
下面是從我的啓動畫面代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
namespace TubeRip
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();
getupdates();
}
private void timer1_Tick(object sender, EventArgs e)
{
timer2.Start();
}
private void timer2_Tick_1(object sender, EventArgs e)
{
timer1.Stop();
label1.Text = "Loading Core Components..." + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 20)
{
progressBar1.Value += 1;
}
else
{
timer3.Start();
}
}
private void end()
{
timer7.Stop();
mainpage home = new mainpage();
home.Show();
this.Dispose(false);
}
private void timer3_Tick(object sender, EventArgs e)
{
timer2.Stop();
label1.Text = "Loading Encryption Algorithyms..." + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 40)
{
progressBar1.Value += 1;
}
else
{
timer4.Start();
}
}
private void timer4_Tick(object sender, EventArgs e)
{
timer3.Stop();
label1.Text = "Enabling Download Services..." + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 60)
{
progressBar1.Value += 1;
}
else
{
timer5.Start();
}
}
private void timer5_Tick(object sender, EventArgs e)
{
timer4.Stop();
label1.Text = "Disabling Youtube's Download Protection..." + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 80)
{
progressBar1.Value += 1;
}
else
{
timer6.Start();
}
}
private void timer6_Tick(object sender, EventArgs e)
{
timer5.Stop();
label1.Text = "Drawing GUI" + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 90)
{
progressBar1.Value += 1;
}
else
{
timer7.Start();
}
}
private void timer7_Tick(object sender, EventArgs e)
{
timer6.Stop();
label1.Text = "Creating The first Humanlike Robot..." + " " + progressBar1.Value.ToString() + "%";
if (progressBar1.Value < 100)
{
progressBar1.Value += 1;
}
else
{
end();
}
}
private void getupdates()
{
try
{
string updateurl = "http://dl.dropbox.com/u/22054429/TubeRip_version.txt";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(updateurl);
WebResponse response = request.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream(), System.Text.Encoding.GetEncoding("windows-1252"));
string update = sr.ReadToEnd();
int build = Convert.ToInt32(update);
int thisbuild = 2;
if (build > thisbuild)
{
label2.Visible = true;
TubeRip.Properties.Settings.Default.UpdateAvail = true;
}
else
{
label2.Visible = false;
TubeRip.Properties.Settings.Default.UpdateAvail = false;
}
}
catch
{
MessageBox.Show("Unable to connect to update server! Please try again later.");
}
}
}
}
下面是從我的更新代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Net;
namespace TubeRip
{
public partial class updates : Form
{
public updates()
{
InitializeComponent();
}
private void updates_Load(object sender, EventArgs e)
{
Uri update = new Uri("http://dl.dropbox.com/u/22054429/TubeRip_Installer.exe");
webClient1.DownloadFileAsync(update, "update.exe");
webClient1.DownloadProgressChanged +=new DownloadProgressChangedEventHandler(webClient1_DownloadProgressChanged);
webClient1.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient1_DownloadFileCompleted);
}
void webClient1_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
Process.Start("update.exe");
Environment.Exit(0);
}
void webClient1_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
label1.Text = "Downloading Updates Please Wait... " + e.ProgressPercentage.ToString() + "%";
}
}
}
沒有人可以幫助這個,所以我做了一些研究,並決定在webclient中使用UTF-8編碼,而不是拋出這個錯誤。 –