question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swagger Integeration .NetcoreApp3.1

See original GitHub issue

I created a sample app where I copied the basic example from the website (MyFirstService).

The unity integration works out of the box, but when I tried to add the Swagger integration, I just get a

localhost is currently unable to handle this request.
HTTP ERROR 500

I added the following packages:

  • MagicOnion (2.6.3)
  • MagicOnionHosting (2.6.3)
  • MagicOnionHttpGateway (2.6.3)

Are there any other packages I need to add to have the swagger integration work properly?

I tested the swagger in the Sandbox application of the source, and it seemed to work flawlessly, but I noticed it uses .NetCoreApp 2.1.

Might it be an issue with the .NetCoreApp 3.1 which I currently have based my application on or might there be anything else missing?

If it would help I can also upload an example repo with minimal code, if that might help in pinpointing the problem.

The main code I used is:

class Program
{
    static async Task Main(string[] args)
    {
        var magicOnionHost = MagicOnionHost.CreateDefaultBuilder()
            .UseMagicOnion(
                new MagicOnionOptions(isReturnExceptionStackTraceInErrorDetail: true),
                new ServerPort("localhost", 12345, ServerCredentials.Insecure))
            .UseConsoleLifetime()
            .Build();

        var webHost = new WebHostBuilder()
            .ConfigureServices(collection =>
            {
                collection.AddSingleton<MagicOnionServiceDefinition>(magicOnionHost.Services.GetService<MagicOnionHostedServiceDefinition>().ServiceDefinition);
            })
            .UseKestrel()
            .UseStartup<Startup>()
            .UseUrls("http://localhost:5432")
            .Build();

        await Task.WhenAll(webHost.RunAsync(), magicOnionHost.RunAsync());
    }
}

public class Startup
{
    public void Configure(IApplicationBuilder app, MagicOnionServiceDefinition magicOnion)
    {

        app.UseMagicOnionSwagger(magicOnion.MethodHandlers, new SwaggerOptions("MagicOnion.Server", "Swagger Integration Test", "/")
        {
        });
        app.UseMagicOnionHttpGateway(magicOnion.MethodHandlers, new Channel("localhost:12345", ChannelCredentials.Insecure));
    }
}

}


	public interface IMyFirstService : IService<IMyFirstService>
	{
		UnaryResult<int> SumAsync(int x, int y);
	}

	public class MyFirstService : ServiceBase<IMyFirstService>, IMyFirstService
	{
		public async UnaryResult<int> SumAsync(int x, int y)
		{
			Logger.Debug($"Received:{x}, {y}");

			return x + y;
		}
	}

Any help would be appreciated.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
neuecccommented, Jan 9, 2020

thanks! I’ve confirmed this bug and fixed in 3.0.8, all code uses asynchronous only.

0reactions
ktanakajcommented, Jan 9, 2020

Hi! Our team found a solution for the Swagger Integration on netcoreapp3.1.

.ConfigureServices(collection =>
{
    collection.AddSingleton<MagicOnionServiceDefinition>(magicOnionHost.Services.GetService<MagicOnionHostedServiceDefinition>().ServiceDefinition);
    // add the following codes
    collection.Configure<KestrelServerOptions>(options =>
    {
        options.AllowSynchronousIO = true;
    });
})

It is working fine. Please check it and update README.md.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implement Swagger In ASP.net Core 3.1 Web API
The Swagger is a set of rules which provides the users functionality to understand the structure of the REST API, and it can...
Read more >
Adding Swagger to ASP.NET Core 3.1 Web API
In this post, we will understand how can we add Swagger UI in an ASP.NET Core 3.1 Web API project.
Read more >
Swagger UI interface in ASP.NET Core 3.1 - Nicky Liu - Medium
Step 1. Create an ASP.NET Core Web Application and select API ... the Swagger generator, defining 1 or more Swagger documents services.
Read more >
Asp.NET Core 3.1 and Swashbuckle.AspNetCore.Swagger
I updated my asp.net core app to v3.1 and updated my Swagger form v5.04 rc to v5.0, and everything stopped to work. The...
Read more >
[ASP.Net Core] Swagger - Integrate API Versioning
Swagger is a powerful open source framework that helps you design, build, document the RESTful APIs. We are going to integrate API Versioning ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found