2015-10-22 27 views
0

在過去的24小時內,Nuget似乎在向我拋出一個奇怪的錯誤。System.Xml.XmlException:給定編碼中的字符無效。第1行,位置1.當使用Nuget

每次我嘗試安裝或卸載包..它失敗,出現以下錯誤:

System.Xml.XmlException: Invalid character in the given encoding. Line 1, position 1. 

總堆棧:

Attempting to gather dependencies information for package 'Microsoft.AspNet.WebApi.Client.5.2.3' with respect to project 'User Interface\SMRH.LPIC.Web', targeting '.NETFramework,Version=v4.5.1' 
Attempting to resolve dependencies for package 'Microsoft.AspNet.WebApi.Client.5.2.3' with DependencyBehavior 'Lowest' 
Resolving actions to install package 'Microsoft.AspNet.WebApi.Client.5.2.3' 
Resolved actions to install package 'Microsoft.AspNet.WebApi.Client.5.2.3' 
For adding package 'Microsoft.AspNet.WebApi.Client.5.2.3' to project 'SMRH.LPIC.Web' that targets 'net451'. 
For adding package 'Microsoft.AspNet.WebApi.Client.5.2.3' to project 'SMRH.LPIC.Web' that targets 'net451'. 
Package 'Microsoft.AspNet.WebApi.Client.5.2.3' already exists in folder 'F:\TFS\DevTeamCode\LPIC\SMRH.LPIC\packages' 
Added reference 'System.Net.Http.Formatting' to project 'SMRH.LPIC.Web'. 
Added package 'Microsoft.AspNet.WebApi.Client.5.2.3' to 'packages.config' 
Successfully installed 'Microsoft.AspNet.WebApi.Client 5.2.3' to SMRH.LPIC.Web 
Added file 'web.config'. 
Install failed. Rolling back... 
System.Xml.XmlException: Invalid character in the given encoding. Line 1, position 1. 
at System.Xml.XmlTextReaderImpl.Throw(Exception e) 
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) 
at System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32& bytesCount, Int32& charsCount) 
at System.Xml.XmlTextReaderImpl.GetChars(Int32 maxCharsCount) 
at System.Xml.XmlTextReaderImpl.ReadData() 
at System.Xml.XmlTextReaderImpl.SwitchEncoding(Encoding newEncoding) 
at System.Xml.XmlTextReaderImpl.SwitchEncodingToUTF8() 
at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl) 
at System.Xml.XmlTextReaderImpl.Read() 
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options) 
at NuGet.ProjectManagement.XmlUtility.LoadSafe(Stream input, LoadOptions options) 
at NuGet.ProjectManagement.XmlUtility.GetDocument(String root, String path) 
at NuGet.ProjectManagement.XmlUtility.GetOrCreateDocument(XName rootName, String root, String path, INuGetProjectContext nuGetProjectContext) 
at NuGet.PackageManagement.VisualStudio.BindingRedirectManager.GetConfiguration() 
at NuGet.PackageManagement.VisualStudio.BindingRedirectManager.AddBindingRedirects(IEnumerable`1 bindingRedirects) 
at NuGet.PackageManagement.VisualStudio.RuntimeHelpers.<AddBindingRedirectsAsync>d__3.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at NuGet.PackageManagement.VisualStudio.RuntimeHelpers.<AddBindingRedirectsAsync>d__2.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at NuGet.PackageManagement.VisualStudio.RuntimeHelpers.<AddBindingRedirectsAsync>d__2.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at NuGet.PackageManagement.VisualStudio.RuntimeHelpers.<AddBindingRedirectsAsync>d__0.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at NuGet.PackageManagement.VisualStudio.VSMSBuildNuGetProjectSystem.<<AddBindingRedirects>b__55_0>d.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread() 
at NuGet.PackageManagement.VisualStudio.VSMSBuildNuGetProjectSystem.AddBindingRedirects() 
at NuGet.ProjectManagement.MSBuildNuGetProject.PostProcessAsync(INuGetProjectContext nuGetProjectContext, CancellationToken token) 
at NuGet.PackageManagement.NuGetPackageManager.<ExecuteNuGetProjectActionsAsync>d__42.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
at NuGet.PackageManagement.NuGetPackageManager.<ExecuteNuGetProjectActionsAsync>d__42.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at NuGet.PackageManagement.UI.UIActionEngine.<ExecuteActionsAsync>d__5.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at NuGet.PackageManagement.UI.UIActionEngine.<PerformActionAsync>d__3.MoveNext() 
========== Finished ========== 

它不會給我什麼文件時,它正在失敗。刪除軟件包文件夾並恢復它也不起作用。

我檢查了web.config,它似乎沒有格式問題。

重新啓動的PC和VS,但沒有運氣。

在C#環境中使用Visual Studio 2015 Enterprise。

+0

而且* 1是第1行第1位的字符? –

+0

我甚至不知道他們在討論什麼文件,然後才能進行調試。 在大多數文件中,它是:「<」 – ArjaaAine

+0

[Wireshark](https://www.wireshark.org/)? –

回答

0

你打開並保存在Visual Studio中的Nuget配置文件?我認爲這裏的問題與Visual Studio編碼文本文件的方式有關。我以前就犯了這個罪。解決方案是在像Notepad ++這樣的像樣的文本編輯器中打開文件並更改編碼。這裏的答案應該幫助 Visual Studio inserts invalid characters in batch files

NuGet的配置文件的默認位置是%APPDATA%\ NuGet \ NuGet.Config(DOS)或$ ENV:APPDATA \ NuGet \ NuGet.Config(PowerShell)。 APPDATA的值是操作系統,系統驅動器和當前用戶依賴。例如: D:\ Users \ username \ AppData \ Roaming \ NuGet \ NuGet.config。

取自https://docs.nuget.org/consume/nuget-config-file

相關問題