gpt4 book ai didi

c# - Dot Net Core 和 Azure 存储 : Could not load file or assembly System, 版本=4.0.0.0

转载 作者:行者123 更新时间:2023-12-03 04:51:17 25 4
gpt4 key购买 nike

我有一个在“netcoreapp1.0”上运行的 Web API,它使用 Azure 存储客户端。访问 blob 根本没有问题,但是当我尝试对表执行任何操作时,它会抛出此错误:

Exception thrown: 'Microsoft.WindowsAzure.Storage.StorageException' in System.Private.CoreLib.ni.dll

Additional information: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

它发生的具体行如下所示:

if (await table.ExistsAsync())

即使删除这个,每当它到达实际对 Azure 进行 HTTP 调用的行时,结果仍然相同。我正在导入“net46”,并且我也尝试在我的project.json中导入“net40”,但没有变化。

上面的代码位于“Cameo.Azure.Storage.Library”中。它以 netstandard1.6 为目标,并引用“WindowsAzure.Storage”:“7.2.0”和“NETStandard.Library”:“1.6.0”。

我的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%" ]
}
}

图书馆的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"
]
}
}
}

最佳答案

您无法在 .NET Core 中使用 .NET 4.0 或 .NET 4.6 程序集。您需要支持 .NET Core(如果有)或目标 .NET Core 的版本。

您在以下部分中所做的只是为了规避 NuGet 目标检查

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

但这不会神奇地使 .NET 4.x 库与 .NET Core 一起工作。 .NET Core 库需要以 netstandard1.xnetcoreapp1.0 为目标(还有一些 - 但不是全部 - 可移植类库专为 Windows Phone 8、8.1 或 10 设计,可能可以工作,但取决于特定的库),以便与 .NET Core 一起运行。

最重要的是,您甚至在项目中引用了 ASP.NET MVC 5 的库,这肯定不会起作用,因为中不再有 System.Web.* .NET Core(与 IIS 紧密耦合)。

您将需要 Microsoft 7.2 版中的 WindowsAzure.Storage 包,该包支持 .NET Core,可以在 NuGet here 上找到。 。

关于c# - Dot Net Core 和 Azure 存储 : Could not load file or assembly System, 版本=4.0.0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39318222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com