swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

/Client/ApiClient.cs(137,51,137,69): error CS1503: Argument 2: cannot convert from 'System.Action<System.IO.Stream>' to 'byte[]'

Open wangzilong opened this issue 8 years ago • 13 comments

Description

There is an error when I build it in Visual Studio .

Error : Client/ApiClient.cs(137,51,137,69): error CS1503: Argument 2: cannot convert from 'System.Action<System.IO.Stream>' to 'byte[]'

screen shot 2018-08-23 at 10 48 55
Swagger-codegen version

2.3.1

Swagger declaration file content or url

swagger.txt

Command line used for generation

java -jar ./swagger-codegen-cli-2.3.1.jar generate -i ./swagger.json -l csharp -o ./csharp

Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

wangzilong avatar Aug 23 '18 09:08 wangzilong

I'm hitting this because I'm building with dotnet core 2.1 and not the .Net Framework.

Compiles but didn't test yet:

            var p = param.Value.Writer;
            MemoryStream ms = new MemoryStream();
            p.Invoke(ms);
            request.AddFile(param.Value.Name, ms.ToArray(), param.Value.FileName, param.Value.ContentType);

JesseKPhillips avatar Jan 04 '19 00:01 JesseKPhillips

Similarly, this compiles for me on .NET framework 4.6:

        request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentLength, param.Value.ContentType);

I'm wondering whether this is caused by a change in RestSharp or a bug in the moustache file.

JarkoDubbeldam avatar Jun 17 '19 13:06 JarkoDubbeldam

request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentLength, param.Value.ContentType);

Same here, and compiled OK on .NET Framework 4.7.2

andres-swax avatar Jun 24 '19 22:06 andres-swax

I'm getting this error too, regardless of the .net framework.

If I add param.Value.ContentLength to:

request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);

Resulting in : request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentLength, param.Value.ContentType);

It solves the problem.

mafigo avatar Apr 17 '20 15:04 mafigo

I'm getting this error too, regardless of the .net framework.

If I add param.Value.ContentLength to:

request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);

Resulting in : request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentLength, param.Value.ContentType);

It solves the problem.

Unfortunately I have this exact same issue with .NET Framework 4.6.1 and latest Open API Code Generator. The code generator is also checking value types for null where they are not defined as nullable, thus, they can never be null.

andrewfinnell avatar May 30 '20 19:05 andrewfinnell

I am also getting the exact issues as @andrewfinnell . For the time being, I have updated this as: request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentLength, param.Value.ContentType); But it would be good to have this resolved at swagger generation end itself.

priyankajayaswal1 avatar Jul 21 '20 11:07 priyankajayaswal1

Having to fix the generated client after every regeneration is a huge pain in the rear. On a .NET Core 2.2 project we have to change this:

request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);

to this:

request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentLength, param.Value.ContentType);

after every regeneration.

The same thing is reproducible when the project is targeting .NET 4.7.2

hyankov avatar Jul 24 '20 17:07 hyankov

I have that error too on .NET 4.7.2

Dragonjester avatar Aug 16 '20 18:08 Dragonjester

I have that error too on .NET 4.7.2

sargemi avatar Sep 15 '20 11:09 sargemi

I have the same error too on .NET 4.6.2

Did anyone found out what the problem is?

AlinIonascu avatar Sep 21 '20 09:09 AlinIonascu

In my case I solve the problem just adding 'ContentLength' parameter in the method that others users said.

The problem for me is that I update the version of RestAPI 105.1.0 to the lasted 106.11.7 (20/12/2020) and the lasted don't have the method olded.

Function only in old version RestAPI 105.1.0. public IRestRequest AddFile(string name, Action writer, string fileName, string contentType = null)

Function changed one parameter added in version RestAPI 106.11.7 public IRestRequest AddFile(string name, Action writer, string fileName, long contentLength, [string contentType = null])

So, method old is obsoleted, update to new method and it's be work like a charm.

richard1994x avatar Dec 20 '20 06:12 richard1994x

What would it take to get this fix into an official release? Having to manually modify these files complicates our CI/CD pipelines.

ElMoselYEE avatar Feb 24 '21 19:02 ElMoselYEE

I'm still running into this issue on .Net 4.8 (which I'm not sure if matters at all) with RestSharp 106.15.0. Would appreciate a fix for it since the manual edit does add efforts to maintain.

nancywan1004 avatar Oct 17 '22 20:10 nancywan1004