Nuget.exe fails with "Could not load file or assembly 'System.Net.Http...' - nuget

I am trying to run "nuget restore" on a server that does not have a Visual Studio installation. But nuget.exe fails immediately. What else needs to be installed for NuGet to run?
C:\Users\kevin>nuget help
Could not load file or assembly 'System.Net.Http,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or
one of its dependencies. The system cannot find the file specified.
Could not load type
'System.Runtime.CompilerServices.IAsyncStateMachine' from assembly
'mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'. Could not load file or assembly
'System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified.

Had this issue as well. Newer versions of NuGet requires .NET 4.5. installing .NET 4.5.2 resolved the issue for me.

Related

Can't use assembly in PowerShell after I've installed the appropriate nuget package

I'm having a problem with a library installed by a NuGet package not working from PowerShell. I've installed it like this (also tried CurrentUser scope and a later version of the package but it makes no difference in the end):
Install-Package Microsoft.Bcl.AsyncInterfaces -Version 1.0.0.0
Microsoft.Bcl.AsyncInterfaces is required by an AWS.Tools module I'm leveraging, but no matter what I do the module assemblies cannot find it. At first I couldn't even add the type into my own session:
Add-Type -AssemblyName Microsoft.Bcl.AsyncInterfaces
Add-Type: Cannot find path '/home/username/src/work-aws/generate-hostname/Microsoft.Bcl.AsyncInterfaces.dll' because it does not exist.
But I was able to load it directly from the package source directory:
Add-Type -Path "$(( Get-Package Microsoft.Bcl.AsyncInterfaces ).Source | Split-Path -Parent)/lib/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll"
However... the assemblies in the AWS module still can't see it. The errors I'm getting from the AWS classes are as follows:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
What am I missing here? I'm not sure how to get this AWS module to see the assembly even after invoking Add-Type to forcibly load the assembly from its fully-qualified path.
I've posted the output of the Exception variable here, though everything still indicates Microsoft.Bcl.AsyncInterfaces can't be found:
ErrorRecord : Exception calling "LoadTable" with "2" argument(s): "The type initializer for 'Amazon.DynamoDBv2.DynamoDBEntryConversion' threw an exception."
WasThrownFromThrowStatement : False
TargetSite : Void ConvertToMethodInvocationException(System.Exception, System.Type, System.String, Int32, System.Reflection.MemberInfo)
StackTrace : at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String
methodName, Int32 numArgs, MemberInfo memberInfo)
at CallSite.Target(Closure , CallSite , Type , Object , String )
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at System.Management.Automation.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Message : Exception calling "LoadTable" with "2" argument(s): "The type initializer for 'Amazon.DynamoDBv2.DynamoDBEntryConversion' threw an exception."
Data : {System.Management.Automation.Interpreter.InterpretedFrameInfo}
InnerException : System.TypeInitializationException: The type initializer for 'Amazon.DynamoDBv2.DynamoDBEntryConversion' threw an exception.
---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The
system cannot find the file specified.
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The
system cannot find the file specified.
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The
system cannot find the file specified.
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The
system cannot find the file specified.
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The
system cannot find the file specified.
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The
system cannot find the file specified.
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The
system cannot find the file specified.
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The
system cannot find the file specified.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at Amazon.DynamoDBv2.DynamoDBEntryConversion.AddConverters(String suffix)
at Amazon.DynamoDBv2.DynamoDBEntryConversion.SetV1Converters()
at Amazon.DynamoDBv2.DynamoDBEntryConversion..ctor(ConversionSchema schema, Boolean isImmutable)
at Amazon.DynamoDBv2.DynamoDBEntryConversion..cctor()
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
File name: 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
--- End of inner exception stack trace ---
at CallSite.Target(Closure , CallSite , Type , Object , String )
HelpLink :
Source : System.Management.Automation
HResult : -2146233087
I found that the reason assemblies installed with Install-Package need to be loaded in this way:
Add-Type -Path "$(( Get-Package Microsoft.Bcl.AsyncInterfaces ).Source | split-path -Parent)/lib/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll"
is because the package/lib directories in the PackagementManagement provider folders are not part of .NET default probe paths. This is less of a problem when you have modules or projects where the assembly paths are configurable in a file, but in a PowerShell session AFAIK you can't modify the assembly probe path. So you have to load the assembly with the full path.
As for why the AWS assemblies in question couldn't find the assembly name after I loaded it into my session, I found the solution as well. After some additional testing, I found that there is an order of operations here; if you add an assembly with Add-Type or [Reflection.Assembly]::LoadFile after another assembly attempts to use it, that second assembly won't be able to find the first assembly for the duration of the PowerShell session. In my case, any assembly making use of Amazon.DynamoDBv2.DynamoDBEntryConversion in some way was failing because it could never locate Microsoft.Bcl.AsyncInterfaces.
My issue here was I would load up a new session, and start running my code forgetting to first use Add-Type to add the Microsoft.Bcl.AsyncInterfaces assembly, then use the AWS library which relied on it. Once the method failed, I added the assembly but it was too late for that session. So the fix here was to do the following:
# Load the Microsoft.Bcl.AsyncInterfaces assembly
Add-Type -Path "$(( Get-Package Microsoft.Bcl.AsyncInterfaces ).Source | split-path -Parent)/lib/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll"
# Read a DynamoDB table from AWS
$regionEndpoint = [RegionEndPoint]::GetBySystemName('us-west-2')
$client = [AmazonDynamoDBClient]::new($regionEndpoint)
[DocumentModel.Table]::LoadTable($client, 'MyDDBTableName') # This is the call that was failing before, succeeds now

System.IO.FileNotFoundException: Could not load assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

Getting this Error In Xamarin Form Android Project I am refering Entity framework library int android project. Error as below
Severity Code Description Project File Line Suppression State Error
Exception while loading assemblies: System.IO.FileNotFoundException:
Could not load assembly 'EntityFramework, Version=6.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089'. Perhaps it doesn't
exist in the Mono for Android profile? File name:
'EntityFramework.dll' at
Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference
reference, ReaderParameters parameters) at
Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver
resolver, ICollection1 assemblies, AssemblyDefinition assembly,
Boolean topLevel) at
Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver
resolver, ICollection1 assemblies, AssemblyDefinition assembly,
Boolean topLevel) at
Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver
resolver, ICollection`1 assemblies, AssemblyDefinition assembly,
Boolean topLevel) at
Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver
resolver) RadLoc.Android C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets
1500
I am stuck here please help me out of this..
Just like #magicandre1981 said. Entity Framework doesn't fit in Xamarin.Android project. You need to use EntityFramework Core.
For a simple jump in and brief introduction, you can refer to Building Android Apps with Entity Framework.
For a windows application with this error:
If your copying the exe to a different folder from /bin/
You also need to include a copy of the application .config file along with the EntityFramework.xml and EntityFramework.SqlServer.xml files.

Calling .Netstandard dll from .net 4.6.2 azure service fabric stateful assembly

I am struggling to call a .netstandard dll from a .Net 4.6.2 azure service fabric statefulservice assembly in Visual Studio 2017 [on windows 7]. I am on latest version of service fabric [5.4.164.9494 and SF SDK version: 2.4.164.9494]
Followed the exact steps as mentioned in Using .net standard 1.5 lib in .net 4.6.2 misses System.Runtime 4.1.0.0. Tried multiple things like creating the netstandard class library from .Net core,.Netstandard and plain old PCL (converted to .net standard from project properties). Nothing works. The project does compile but when I deploy the project to the cluster, The statefulservice never get's initialized and this is the error in the log..
{
"Timestamp": "2017-03-17T09:28:22.8026277-04:00",
"ProviderName": "Microsoft-ServiceFabric-Services",
"Id": 5,
"Message": "RunAsync has failed for a stateful service replica. Application Type Name: ServiceFabricTestType, Application Name: fabric:/ServiceFabricTest, Service Type Name: Stateful1Type, Service Name: fabric:/ServiceFabricTest/Stateful1, Partition Id: 17258b22-c015-4eec-8026-edd3e21fffc4, Replica Id: 131342308870035108, WasCancelled: False, Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
at Stateful1.Stateful1.<RunAsync>d__2.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
at Stateful1.Stateful1.RunAsync(CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.StatefulServiceBase.Microsoft.ServiceFabric.Services.Runtime.IStatefulUserServiceReplica.RunAsync(CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.StatefulServiceReplicaAdapter.<ExecuteRunAsync>d__12.MoveNext()
",
"ProcessId": 22424,
"Level": "Error",
"Keywords": "0x0000F00000000000",
"EventName": "StatefulRunAsyncFailure",
"ActivityID": null,
"RelatedActivityID": null,
"Payload": {
"applicationTypeName": "ServiceFabricTestType",
"applicationName": "fabric:/ServiceFabricTest",
"serviceTypeName": "Stateful1Type",
"serviceName": "fabric:/ServiceFabricTest/Stateful1",
"partitionId": "17258b22-c015-4eec-8026-edd3e21fffc4",
"replicaId": 131342308870035108,
"wasCanceled": false,
"exception": "System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
at Stateful1.Stateful1.<RunAsync>d__2.MoveNext()
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
at Stateful1.Stateful1.RunAsync(CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.StatefulServiceBase.Microsoft.ServiceFabric.Services.Runtime.IStatefulUserServiceReplica.RunAsync(CancellationToken cancellationToken)
at Microsoft.ServiceFabric.Services.Runtime.StatefulServiceReplicaAdapter.<ExecuteRunAsync>d__12.MoveNext()
"
}
}
Any help is appreciated..
Are you running a SF cluster with Windows Server 2012R2 or 2016? The default option from Azure portal is still 2012R2 and only has .NET 4.5.1 unless you install 4.6.2 by yourself (manual or through script)

The type 'MaxLengthAttribute' exists in both 'EntityFramework, and 'System.ComponentModel.DataAnnotations

I am doing some spring cleaning on a legacy Web Api 2 project (target 4.5). As part of the the nuget updates, I moved Microsoft.AspNet.WebApi.HelpPage from version 5.0.0 to 5.2.3. Once I do that, I am getting the following message:
Error CS0433 The type 'MaxLengthAttribute' exists in both
'EntityFramework, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' and
'System.ComponentModel.DataAnnotations, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35'
It looks like this was a problem a while back when they moved that class from EF to DataAnnotations and the solution was to upgrade EF. Since I have the most recent stable version of EF (5.2.3), I am not sure what else to do. I tried removing System.ComponentModel.DataAnnotations from the using statements, but then it doesn't pick up the EF MaxLengthAttribute. Cleaning and rebuilding the solution also does not work.
Any pointers are appreciated.

Add-Type cannot find file

Trying to Add-Type -AssemblyName System.DirectoryServices.AccountManagement fails with:
Add-Type : Could not load file or assembly
'System.DirectoryServices.AccountManagement, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its
dependencies. The system cannot find the file specified.
Using clean installation of Windows Server 2008R2
After doing some experimentation, I have used Add features wizard in Server manager and added .NET Framework 3.5.1. After this all works well. I wonder why installing latest .NET framework (4.5.2) did not help.