/Client/ApiClient.cs(137,51,137,69): error CS1503: Argument 2: cannot convert from 'System.Action<System.IO.Stream>' to 'byte[]'
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[]'
Swagger-codegen version
2.3.1
Swagger declaration file content or url
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
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);
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.
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
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.
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.
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.
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
I have that error too on .NET 4.7.2
I have that error too on .NET 4.7.2
I have the same error too on .NET 4.6.2
Did anyone found out what the problem is?
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
Function changed one parameter added in version RestAPI 106.11.7
public IRestRequest AddFile(string name, Action
So, method old is obsoleted, update to new method and it's be work like a charm.
What would it take to get this fix into an official release? Having to manually modify these files complicates our CI/CD pipelines.
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.