简体   繁体   English

点网核心和Azure存储:无法加载文件或程序集系统,版本= 4.0.0.0

[英]Dot Net Core and Azure Storage: Could not load file or assembly System, Version=4.0.0.0

I have a web API running on "netcoreapp1.0" which is using Azure Storage Client. 我在使用Azure Storage Client的“ netcoreapp1.0”上运行一个Web API。 Accessing blobs has no issue at all but when I try execute any operation with tables it throws me this error: 访问blob根本没有问题,但是当我尝试对表执行任何操作时,会引发以下错误:

Exception thrown: 'Microsoft.WindowsAzure.Storage.StorageException' in System.Private.CoreLib.ni.dll 抛出异常:System.Private.CoreLib.ni.dll中的'Microsoft.WindowsAzure.Storage.StorageException'

Additional information: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. 附加信息:无法加载文件或程序集'System,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'。 The system cannot find the file specified. 该系统找不到指定的文件。

The specific line it happens looks like this: 它发生的特定行如下所示:

if (await table.ExistsAsync()) 如果(await table.ExistsAsync())

Even removing this, whenever it hits a line where it would actually do a HTTP call to Azure it still results the same. 即使将其删除,只要它碰到实际将对Azure进行HTTP调用的行,它的结果仍然相同。 I am importing "net46", and I have tried also importing in my project.json "net40", but no change. 我正在导入“ net46”,并且我也尝试在project.json中导入“ net40”,但没有任何变化。

The code above is living in "Cameo.Azure.Storage.Library". 上面的代码位于“ Cameo.Azure.Storage.Library”中。 It is targeting netstandard1.6 and it is referencing "WindowsAzure.Storage": "7.2.0" and "NETStandard.Library": "1.6.0". 它以netstandard1.6为目标,并引用“ WindowsAzure.Storage”:“ 7.2.0”和“ NETStandard.Library”:“ 1.6.0”。

My project.json is below: 我的project.json在下面:

{
  "dependencies": {
    "Cameo.Azure.Storage.Library": "1.0.0-*",
    "Cameo.GeoLocation": "1.0.0-*",
    "LightInject": "4.0.11",
    "LightInject.Microsoft.DependencyInjection": "1.0.1",
    "LocationService.Domain": "1.0.0-*",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Swashbuckle": "6.0.0-beta902"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "net46",
        "net40"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "xmlDoc": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

The librarie's project.json librarie的project.json

{
  "version": "1.0.0-*",

  "dependencies": {
    "Cameo.Azure.Storage.Interface": "1.0.0-*",
    "LightInject": "4.0.11",
    "Microsoft.Extensions.Configuration": "1.0.0",
    "Microsoft.Extensions.Options": "1.0.0",
    "NETStandard.Library": "1.6.0",
    "WindowsAzure.Storage": "7.2.0"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": [
        "net46"
      ]
    }
  }
}

You can't use .NET 4.0 or .NET 4.6 assemblies in .NET Core. 您不能在.NET Core中使用.NET 4.0或.NET 4.6程序集。 You need either versions that support .NET Core (if there are any) or target .NET Core. 您需要支持.NET Core的版本(如果有)或目标.NET Core。

What you did in the following section is only to circumvent NuGet target check 您在以下部分中所做的只是绕过NuGet目标检查

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "net46",
        "net40"
      ]
    }
  },

But this will not magically make the .NET 4.x libraries work with .NET Core. 但这不会神奇地使.NET 4.x库与.NET Core一起使用。 .NET Core library need to target netstandard1.x or netcoreapp1.0 (there are are also some - but not all - Portable Class Libraries that were designed for Windows Phone 8, 8.1 or 10 that may work, but depends on the specific library) in order to run with .NET Core. .NET Core库需要以netstandard1.xnetcoreapp1.0为目标(也有一些 -但不是全部-专为Windows Phone netcoreapp1.0或10设计的可移植类库可能有效,但取决于特定的库)为了与.NET Core一起运行。

On top of that, you are even referencing an library for ASP.NET MVC 5 in your project, which is for sure not going to work as there is no System.Web.* anymore in .NET Core (its tightly coupled to IIS). 最重要的是,您甚至在项目中引用ASP.NET MVC 5的库,由于.NET Core(与IIS紧密耦合)中不再有System.Web.* ,因此它肯定无法正常工作System.Web.*

You will need the WindowsAzure.Storage package from Microsoft in the version 7.2, which supports .NET Core and can be found on NuGet here . 您将需要7.2版的Microsoft WindowsAzure.Storage软件包,该软件包支持.NET Core,可以在NuGet 此处找到。

Changing the project.json in web API to this has solved the issue. 将Web API中的project.json更改为此可以解决问题。

"frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "portable-net45+win8"
      ]
    }
  }

You can only import core or portable (PCL) version of the framework. 您只能导入框架的核心或便携式(PCL)版本。 Reference: 参考:

https://blogs.msdn.microsoft.com/cesardelatorre/2016/06/28/running-net-core-apps-on-multiple-frameworks-and-what-the-target-framework-monikers-tfms-are-about/ https://blogs.msdn.microsoft.com/cesardelatorre/2016/06/28/running-net-core-apps-on-multiple-frameworks-and-what-the-target-framework-monikers-tfms-are-关于/

It is important to use “imports” only for versions of .NET Core and PCL (Portable Class Libraries). 重要的是,仅对.NET Core和PCL(便携式类库)的版本使用“导入”。 Using it with TFMS from the traditional .NET Framework can cause issues or malfunction. 将其与传统.NET Framework中的TFMS一起使用可能会导致问题或故障。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS Lambda,.Net Core和MySql:无法加载文件或程序集'System.Diagnostics.TraceSource,Version = 4.0.0.0 - AWS Lambda, .Net Core, & MySql: Could not load file or assembly 'System.Diagnostics.TraceSource, Version=4.0.0.0 .NET Core 3.1 和无法加载文件或程序集 System.Data.Entity,版本 = 4.0.0.0 - .NET Core 3.1 and Could not load file or assembly System.Data.Entity, Version=4.0.0.0 获取无法加载文件或程序集'System.Core,Version = 4.0.0.0 ..'在使用moq在asp.net核心中进行单元测试时 - Getting Could not load file or assembly 'System.Core, Version=4.0.0.0..' While doing unit testing in asp.net core with moq System.IO.FileNotFoundException:无法加载文件或程序集'System.Net.Security,Version = 4.0.0.0 - System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Security, Version=4.0.0.0 无法加载文件或程序集'System.Collections,版本= 4.0.0.0 - Could not load file or assembly 'System.Collections, Version=4.0.0.0 无法加载文件或程序集'System.Data.SqlServerCe,Version = 4.0.0.0 - Could not load file or assembly 'System.Data.SqlServerCe, Version=4.0.0.0 无法加载文件或程序集 'System.Web.Services,版本 = 4.0.0.0 - Could not load file or assembly 'System.Web.Services, Version=4.0.0.0 无法加载文件或程序集FSharp.Core,Version = 4.0.0.0 Azure Web Role - Could not load file or assembly FSharp.Core, Version=4.0.0.0 Azure Web Role Azure应用服务无法加载文件或程序集'System.Data.SqlServerCe,Version = 4.0.0.0 - Azure app services Could not load file or assembly 'System.Data.SqlServerCe, Version=4.0.0.0 无法加载文件或程序集'System.ServiceModel.Web,版本= 4.0.0.0' - Could not load file or assembly 'System.ServiceModel.Web, Version=4.0.0.0'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM