Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'System.Runtime, Version=4.1.0.0' in .NET Core

Tags:

c#

.net-core

Unhandled Exception: 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.

   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
   at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
   at System.AppDomain.GetTargetFrameworkName()

I using AssemblyLoadContext in my application so I have "System.Runtime.Loader": "4.0.0" as dependency but after publish my project I have above error.

dotnet --version
1.0.0-preview2-003121

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    },
    "CommandLineArgumentsParser": "3.0.4",
    "System.Runtime.Loader": "4.0.0",
    "Microsoft.Extensions.DependencyModel": "1.0.0",
    "System.Runtime": "4.1.0"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  }
}

with visual studio I can run my application but with dotnet command line I have above error. Can somebody help me ?

like image 812
NBM Avatar asked Sep 13 '16 04:09

NBM


1 Answers

You "created project as .NET 4.6.2" and you're trying to compile with dotnet core. You need to choose between the first or the second. Your error is happening because your got .net 4.6.2 referenced by the project file vcxproj, and dotnet won't be able to make it work.

Today, you might want to clean your vcxproj file as well as your dotnet configuration, migrate your sources to a new project (I recommend dotnet core 2) and this should run.

like image 141
Soleil Avatar answered Nov 11 '22 09:11

Soleil