Error integrating OpenApi in .net4.8 winform application

ClemensLinders

New member
Joined
Oct 20, 2021
Messages
4
Programming Experience
10+
Hi,

I am trying to see if OpenApi is something for us.

I created a .Net5 solution with two projects in my solution:
- OpenApi (the standard temperature API)
- Blazor webassembly that uses the OpenApi as a client.

This works, each time I open the Blazor app I get a new random temperature lsiting.

Now I added a third project to the solution.
A .Net 4.8 project.

I add Connected service, I can select OpenApi (only choice available).
As a file I select my swagger.json file (same as I did in my blazor app).


But now I get the error:
Failed adding service reference(s). Object reference not set to an instance of an object.



What am I doing wrong or can I simply not use Open Api web services in .Net 4+??




Kind regards,



Clemens Linders
 
Do you have a callstack for where the error occurs?
 
If you got an exception while running in the debugger, click on the Exception details button.
 
Hi Skydiver,

I had a few days off, but I am back.

In my solution explorer I click on my project with the right mouse button: Add Service reference.

I can now click on Add service reference. If I do this I get: Add service reference and I click on OpenApi and Next.

Now I can select a file and I select my swagger.json file.

If I now click on Finish I get to see my error: Failed adding service(s). Object not set to an instance of an object.


So I do not even get to run my application and I do not have a callstack.


Kind regards,




Clemens Linders
 
Sorry, I can't help. Sounds like a new feature for VS. In the old Add Service feature I used, I had to actually point to a live running SOAP web service so that it could generate the proxies. This was over 10 years ago Apparently VS now supports pointing to a static JSON file that describes a REST web service. I've no experience with that.
 
Hi Skydiver,

Thanks for the effort.

I did find that starting a Winform (.net 4.5 and installing Swashbuckle.Net45) in a new solution was a solution to this specific problem.
However continuing after that with the Swagger.Json (connecting to/consuming the service, etc) was not clear and I could not find any samples (all the samples I found are about .Net core).

But shows how to connect to an API from Windows Forms.

This way is a bit older and does not include Swagger, but it works.

I posted my solution so that perhaps others can benefit.




Kind regards,



Clemens Linders
 
As a quick aside .NET Framework 4.5 is out of support. I think the lowest supported version is .NET Framework 4.6.2.
 
Back
Top Bottom