aliyun / aliyun-oss-csharp-sdk

Aliyun OSS SDK for C#
MIT License
379 stars 204 forks source link

在window下运行报错,但在mac上可以成功 #122

Open spiderpoison opened 3 years ago

spiderpoison commented 3 years ago

简单的示例程序: var client = new OssClient("http://oss-cn-hangzhou.aliyuncs.com", "xx","xxx"); client.GetObject("xxx", "xxx");

csproj文件如下: `

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="Aliyun.OSS.SDK" Version="2.13.0" />
</ItemGroup>

`

在mac可以顺利运行,但在windows报错: Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at Aliyun.OSS.Common.Communication.HttpExtensions.AddInternal(WebHeaderCollection headers, String key, String value) at Aliyun.OSS.Common.Communication.HttpFactory.SetRequestHeaders(HttpWebRequest webRequest, ServiceRequest serviceRequest, ClientConfiguration configurati on) at Aliyun.OSS.Common.Communication.HttpFactory.CreateWebRequest(ServiceRequest serviceRequest, ClientConfiguration configuration) at Aliyun.OSS.Common.Communication.ServiceClientImpl.SendCore(ServiceRequest serviceRequest, ExecutionContext context) at Aliyun.OSS.Common.Communication.ServiceClient.Send(ServiceRequest request, ExecutionContext context) at Aliyun.OSS.Common.Communication.RetryableServiceClient.SendImpl(ServiceRequest request, ExecutionContext context, Int32 retryTimes) at Aliyun.OSS.Common.Communication.RetryableServiceClient.Send(ServiceRequest request, ExecutionContext context) at Aliyun.OSS.Commands.OssCommand.Execute() at Aliyun.OSS.Commands.OssCommand1.Execute() at Aliyun.OSS.OssClient.GetObject(GetObjectRequest getObjectRequest) at Aliyun.OSS.OssClient.GetObject(String bucketName, String key) at ossdemo.Program.Main(String[] args) in F:\Temp\ossdemo\ossdemo\Program.cs:line 12 `

esterkaufman commented 3 years ago

Hi, I had the same issue, and problem might be solved by updating .net version you are using to one of the .Net Framework 4.x versions.

So either you should:

  1. Change your project from .NetCore x to .Net Framework 4.x
  2. Or you can use in .Net Standard 2.x version class library

Hope this will help someone else.

Janet-Baker commented 1 week ago

2024年了,3年过去了,这个问题依然没有修复…… 看来是真不管issue啊?

liaodalin19903 commented 5 days ago

如果你是windows系统: 看下构建的是 net framwork 还是 .net or netcore 运行时,

1)如果是 net framework,需要依赖 https://www.nuget.org/packages/Aliyun.OSS.SDK

2)如果是.net 或者 net core 的,需要依赖 https://www.nuget.org/packages/Aliyun.OSS.SDK.NetCore

另外,github上有相应的示例工程,用户可以参考。https://github.com/aliyun/aliyun-oss-csharp-sdk/tree/master/samples