Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.Xml.XmlException:给定编码中的字符无效。第1行,位置1。使用Nuget时_C#_Visual Studio 2015_Nuget_Admin - Fatal编程技术网

C# System.Xml.XmlException:给定编码中的字符无效。第1行,位置1。使用Nuget时

C# System.Xml.XmlException:给定编码中的字符无效。第1行,位置1。使用Nuget时,c#,visual-studio-2015,nuget,admin,C#,Visual Studio 2015,Nuget,Admin,在过去的24小时里,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' wi

在过去的24小时里,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 ==========
它不会告诉我它失败的文件是什么。删除packages文件夹并还原它也不起作用

我已经检查了web.config,它似乎没有格式问题

重新启动PC和VS,但运气不佳


使用Visual Studio 2015 Enterprise,使用C环境

是否在visual studio中打开并保存了nuget配置文件?我认为这里的问题在于VisualStudio编码文本文件的方式。我以前也犯过这样的错误。解决方案是在一个像样的文本编辑器(如记事本+)中打开文件并更改编码。这里的答案应该有帮助 .

NuGet的配置文件的默认位置是%APPDATA%\NuGet\NuGet.Config DOS或$ENV:APPDATA\NuGet\NuGet.Config PowerShell。APPDATA的值取决于操作系统、系统驱动器和当前用户。例如: D:\Users\username\AppData\Roaming\NuGet\NuGet.config


摘自

您是否在visual studio中打开并保存了nuget配置文件?我认为这里的问题在于VisualStudio编码文本文件的方式。我以前也犯过这样的错误。解决方案是在一个像样的文本编辑器(如记事本+)中打开文件并更改编码。这里的答案应该有帮助 .

NuGet的配置文件的默认位置是%APPDATA%\NuGet\NuGet.Config DOS或$ENV:APPDATA\NuGet\NuGet.Config PowerShell。APPDATA的值取决于操作系统、系统驱动器和当前用户。例如: D:\Users\username\AppData\Roaming\NuGet\NuGet.config


取自

我发现这是一个编码问题。 如果用visual studio代码打开该文件,您将看到编码可能是UTF-8,并且BOM应该显示在左下角。一些解析器在解释文件时难以读取BOM表

尝试将文件保存为vs code中的UTF-8编码,方法是单击编码并选择“另存为”选项


希望这有帮助。

我发现这是一个编码问题。 如果用visual studio代码打开该文件,您将看到编码可能是UTF-8,并且BOM应该显示在左下角。一些解析器在解释文件时难以读取BOM表

尝试将文件保存为vs code中的UTF-8编码,方法是单击编码并选择“另存为”选项


希望这能有所帮助。

我也面临着同样的问题。它与nuget缓存有关。我清除了缓存并再次运行了dotnet restore命令,它成功了

清除缓存的命令:dotnet nuget locals all-clear


要恢复nuget软件包:dotnet restore-无缓存

我面临着完全相同的问题。它与nuget缓存有关。我清除了缓存并再次运行了dotnet restore命令,它成功了

清除缓存的命令:dotnet nuget locals all-clear


要还原nuget软件包:dotnet restore-no cache

以及第1行位置1处的字符是什么?在调试此文件之前,我甚至不知道他们在谈论什么文件。在大多数文件中是:?当然,在大多数文件中,如果我能找出哪个文件是没有的,我就不会在这里。谢谢Wireshark,我会试试看它是否有用。第1行位置1的字符是什么?在我调试之前,我甚至不知道他们在谈论什么文件。在大多数文件中是:?当然,在大多数文件中,如果我能找出哪个文件是没有的,我就不会在这里。谢谢Wireshark,我会试试看它是否有用。