Nuget - 未将对象引用设置为对象的实例

时间:2021-09-21 16:56:31

I have a problem with nuget package manager in vs 2015. Some packages like Unity has been installed with no problem. Some packages like EF had problems while installing. Some packages like Automapper had the same problem but when I installed another version of this package, It installed fine.

我在vs 2015中遇到了nuget包管理器的问题。像Unity这样的软件包安装没有问题。像EF这样的软件包在安装时遇到了问题。像Automapper这样的一些软件包有同样的问题但是当我安装了这个软件包的另一个版本时,安装得很好。

here is the output:

这是输出:

System.NullReferenceException: Object reference not set to an instance of an object.


at NuGet.Protocol.Core.v3.GlobalPackagesFolderUtility.<AddPackageAsync>d__1.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 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at NuGet.Protocol.Core.v3.DownloadResourceV3.<GetDownloadResourceResultAsync>d__4.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.PackageDownloader.<GetDownloadResourceResultAsync>d__1.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 System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   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 ==========

3 个解决方案

#1


7  

It is a common problem with the use of the new protocol (version 3) nuget used in Visual Studio 2015. It is with multiple nuget packages, for example Microsoft.Owin 3.0.1. To fix this go to:

使用Visual Studio 2015中使用的新协议(版本3)nuget是一个常见问题。它具有多个nuget包,例如Microsoft.Owin 3.0.1。要解决这个问题,请访问:

C:\Users\<your user name>\AppData\Roaming\NuGet

And edit the XML configuration file, commenting the line of protocol 3:

编辑XML配置文件,注释协议3的行:

<!-- add key = "nuget.org" value = "https://api.nuget.org/v3/index.json" protocolVersion = "3" /-->
<add key = "nuget.org" value = "https://www.nuget.org/api/v2/" /> 

Maintenance settings for version 2. Save and restart visual studio 2015. You should now restore the nuget packages without problems.

版本2的维护设置。保存并重新启动visual studio 2015.您现在应该可以毫无问题地恢复nuget包。

#2


0  

When i've had Nuget problems in the past these are the steps i've done:

当我过去遇到Nuget问题时,这些是我已经完成的步骤:

1) Use Nuget package manager to remove out of project(s)

1)使用Nuget包管理器删除项目

2) Clean and Build (you'll have errors because you do longer have the references 2) Make sure the packages were removed from your packages.config (if not, delete and repeat step 2)

2)清理和构建(你会有错误,因为你有更长的引用2)确保从packages.config中删除包(如果没有,删除并重复步骤2)

3) Make sure the .dlls were removed from your bin folder (if not, delete and repeat step 2)

3)确保.dll已从bin文件夹中删除(如果没有,请删除并重复步骤2)

4) Add packages back in and rebuild. Ensure the packages were added to packages.config (with appropriate version) and .dlls were added back to the bin folder (with appropriate version).

4)重新添加包并重建。确保将包添加到packages.config(具有适当的版本)并将.dll添加回bin文件夹(具有适当的版本)。

#3


0  

I am running VS 2017, but was having this error with the TFS build server during the "dotnet restore" task. The issue was we had an internal local file share, but the nuget.config had protocolVersion="3" for that entry. After removing that property, the build was successful.

我正在运行VS 2017,但在“dotnet restore”任务期间与TFS构建服务器出现此错误。问题是我们有一个内部本地文件共享,但是nuget.config对该条目有protocolVersion =“3”。删除该属性后,构建成功。

#1


7  

It is a common problem with the use of the new protocol (version 3) nuget used in Visual Studio 2015. It is with multiple nuget packages, for example Microsoft.Owin 3.0.1. To fix this go to:

使用Visual Studio 2015中使用的新协议(版本3)nuget是一个常见问题。它具有多个nuget包,例如Microsoft.Owin 3.0.1。要解决这个问题,请访问:

C:\Users\<your user name>\AppData\Roaming\NuGet

And edit the XML configuration file, commenting the line of protocol 3:

编辑XML配置文件,注释协议3的行:

<!-- add key = "nuget.org" value = "https://api.nuget.org/v3/index.json" protocolVersion = "3" /-->
<add key = "nuget.org" value = "https://www.nuget.org/api/v2/" /> 

Maintenance settings for version 2. Save and restart visual studio 2015. You should now restore the nuget packages without problems.

版本2的维护设置。保存并重新启动visual studio 2015.您现在应该可以毫无问题地恢复nuget包。

#2


0  

When i've had Nuget problems in the past these are the steps i've done:

当我过去遇到Nuget问题时,这些是我已经完成的步骤:

1) Use Nuget package manager to remove out of project(s)

1)使用Nuget包管理器删除项目

2) Clean and Build (you'll have errors because you do longer have the references 2) Make sure the packages were removed from your packages.config (if not, delete and repeat step 2)

2)清理和构建(你会有错误,因为你有更长的引用2)确保从packages.config中删除包(如果没有,删除并重复步骤2)

3) Make sure the .dlls were removed from your bin folder (if not, delete and repeat step 2)

3)确保.dll已从bin文件夹中删除(如果没有,请删除并重复步骤2)

4) Add packages back in and rebuild. Ensure the packages were added to packages.config (with appropriate version) and .dlls were added back to the bin folder (with appropriate version).

4)重新添加包并重建。确保将包添加到packages.config(具有适当的版本)并将.dll添加回bin文件夹(具有适当的版本)。

#3


0  

I am running VS 2017, but was having this error with the TFS build server during the "dotnet restore" task. The issue was we had an internal local file share, but the nuget.config had protocolVersion="3" for that entry. After removing that property, the build was successful.

我正在运行VS 2017,但在“dotnet restore”任务期间与TFS构建服务器出现此错误。问题是我们有一个内部本地文件共享,但是nuget.config对该条目有protocolVersion =“3”。删除该属性后,构建成功。