Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wangzilong opened this issue Aug 23, 2018 · 14 comments

Comments

@wangzilong
Copy link

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
@JesseKPhillips
Copy link

JesseKPhillips commented Jan 4, 2019

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);

@JarkoDubbeldam
Copy link

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.

@andres-swax
Copy link

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

@mafigo
Copy link

mafigo commented Apr 17, 2020

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.

@andrewfinnell
Copy link

andrewfinnell commented May 30, 2020

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.

@priyankajayaswal1
Copy link

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.

@hyankov
Copy link

hyankov commented Jul 24, 2020

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

@Dragonjester
Copy link

I have that error too on .NET 4.7.2

1 similar comment
@sargemi
Copy link

sargemi commented Sep 15, 2020

I have that error too on .NET 4.7.2

@AlinIonascu
Copy link

AlinIonascu commented Sep 21, 2020

I have the same error too on .NET 4.6.2

Did anyone found out what the problem is?

@richard1994x
Copy link

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.

@ElMoselYEE
Copy link

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

@nancywan1004
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

15 participants