ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.39k stars 1.64k forks source link

Can't make run my Gateway #90

Closed piyey closed 7 years ago

piyey commented 7 years ago

I don't get Ocelot to work, I do create a new project, update all references and install Ocelot to the project, then I create the configuration.json file with one route to one of my service, but when I run the project (gateway), it keep loading. What am I doing wrong? Sorry if this doesn't go here, but I didn't find where to post my question. Regards!

TomPallister commented 7 years ago

Hi @piyey can you post your configuration.json here? Hide anything that might be sensitive! Also are you using the latest nuget package or Ocelot from source?

piyey commented 7 years ago

Hi @TomPallister ,thanks for your answer. This is my configuration.json file:

{
  "ReRoutes": [
    {
      "DownstreamPathTemplate": "/api/Clientes/BuscarPorId/{id}",
      "DownstreamScheme": "http",
      "DownstreamHost": "localhost",
      "DownstreamPort": 59293,
      "UpstreamPathTemplate": "/BuscarClientePorId/{id}",
      "UpstreamHttpMethod": "Get"
    }
  ]
}
piyey commented 7 years ago

I got this error in debug:

Excepción producida: 'System.EntryPointNotFoundException' en System.Private.CoreLib.ni.dll Excepción producida: 'System.DllNotFoundException' en System.Private.CoreLib.ni.dll System.DllNotFoundException: Unable to load DLL 'combase.dll': No se puede encontrar el módulo especificado. (Exception from HRESULT: 0x8007007E) at Microsoft.Win32.UnsafeNativeMethods.RoGetActivationFactory(String activatableClassId, Guid& iid, Object& factory) at System.Threading.Tasks.AsyncCausalityTracer..cctor()

TomPallister commented 7 years ago

I have no idea what that exception is! What OS are you using?

piyey commented 7 years ago

Windows 7 x64

somusun3 commented 7 years ago

@piyey, I had a similar issue when I try o run the Ocelot.ManualTest project. Where the gateway is struck in host.Run(); and all the internal request threads are exited.

So I just created a new project with new startup file

`public class Startup { public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddJsonFile("configuration.json") .AddEnvironmentVariables(); Configuration = builder.Build(); }

    public IConfigurationRoot Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddMvc();

        Action<ConfigurationBuilderCachePart> settings = (x) =>
        {
            x.WithMicrosoftLogging(log =>
            {
                log.AddConsole(LogLevel.Debug);
            })
            .WithDictionaryHandle();
        };

        services.AddOcelot(Configuration, settings);

    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseBrowserLink();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseStaticFiles();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

        app.UseOcelot().Wait();
    }
}`

I think something in the public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) method is causing the issue. Still did not get time to see why.

But the new startup template works.

NOTE : I did not got any exception by the way. For me it was just kept loading

TomPallister commented 7 years ago

I wonder if its something to do with the app.UseOcelot().Wait(). I possibly need to stick ConfigureAwait(false) on all the calls down the stack from this point. I wasn't sure how .NET core was going to work with calling .Wait() on a task during Startup in terms of deadlocking and I have had no problems with deadlocking myself.

TomPallister commented 7 years ago

Further research shows http://stackoverflow.com/questions/41128131/task-start-net-core-unable-to-load-dll-combase-dll-error-windows-7

and

https://social.msdn.microsoft.com/Forums/vstudio/en-US/9ad1dcb7-3521-4e80-9023-fd26ccb76a0c/taskstart-on-net-core-throws-missing-combasedll-error-on-windows-7-dev-machine?forum=netfxbcl

seems to be a win7 / .net core issue not specific to Ocelot :(

piyey commented 7 years ago

Thanks @somusun3 , I have tried your solution, but I still get errors:

Excepción producida: 'System.EntryPointNotFoundException' en System.Private.CoreLib.ni.dll
Excepción producida: 'System.BadImageFormatException' en System.Private.CoreLib.ni.dll
System.BadImageFormatException: Se ha intentado cargar un programa con un formato incorrecto. (Exception from HRESULT: 0x8007000B)
   at Microsoft.Win32.UnsafeNativeMethods.RoGetActivationFactory(String activatableClassId, Guid& iid, Object& factory)
   at System.Threading.Tasks.AsyncCausalityTracer..cctor()Excepción producida: 'System.EntryPointNotFoundException' en System.Private.CoreLib.ni.dll
Excepción producida: 'System.BadImageFormatException' en System.Private.CoreLib.ni.dll
System.BadImageFormatException: Se ha intentado cargar un programa con un formato incorrecto. (Exception from HRESULT: 0x8007000B)
   at Microsoft.Win32.UnsafeNativeMethods.RoGetActivationFactory(String activatableClassId, Guid& iid, Object& factory)
   at System.Threading.Tasks.AsyncCausalityTracer..cctor()

@TomPallister , Thanks for your answer, I have read that posts and I see is a problem with combase.dll, I have avoided to use await, but now I get error cited before.

Regards!

juancash commented 7 years ago

@piyey I´ve seen that you are from Nicaragua. I´m from Spain. If you want you can write me by private in Spanish to explain me better what is your problem in order to try to help you. I have done some mini projects with ocelot to test it and I didn´t have any problems. You should be able to create a simple web api project with only ocelot dll without problems too. What kind of project are you creating? What Visual Studio are you using? Do you have installed the .Net Core SDK 1.1?

piyey commented 7 years ago

Hello @juancash , thanks for your interest in help. I fiinally find where was my problem, looks like it was me.

I just copy all configuration from the guide in Getting Started site in Startup section on wich it remove .UseIISIntegration() from Program Class. Looks like it is required in my enviroment to run the application. I created a new project and included this configuration and now it works perfectly.

Sorry if I spent your time, but maybe it help someone else having the same problem than me. Thanks to all, specially Tom for create this spectacullar library!!!

Regards!

Gracias @juancash , para la próxima ya se con quién abocarme si necesito ayuda en español :)

TomPallister commented 7 years ago

@piyey Don't worry about time :) It's good to have people interested in the project.