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

builder.Host.UseAgileConfig()与SkyWalking不兼容 #105

Open
gudieaofei opened this issue Oct 12, 2022 · 3 comments
Open

builder.Host.UseAgileConfig()与SkyWalking不兼容 #105

gudieaofei opened this issue Oct 12, 2022 · 3 comments

Comments

@gudieaofei
Copy link

当项目引入SkyWalking并设置了环境变量:
Environment.SetEnvironmentVariable("ASPNETCORE_HOSTINGSTARTUPASSEMBLIES", "SkyAPM.Agent.AspNetCore");
调用builder.Host.UseAgileConfig()会报错:
System.InvalidOperationException:“Unable to resolve service for type 'Microsoft.Extensions.Hosting.IHostEnvironment' while attempting to activate 'SkyApm.Agent.Hosting.HostingEnvironmentProvider'.”
但如果使用以下方式是可以正常使用的,麻烦看下如何处理
builder.Host.ConfigureAppConfiguration((context, config) => { var configClient = new ConfigClient(); config.AddAgileConfig(configClient); });

@gudieaofei gudieaofei changed the title builder.Host.UseAgileConfig会与SkyWalking冲突 builder.Host.UseAgileConfig与SkyWalking不兼容 Oct 12, 2022
@gudieaofei gudieaofei changed the title builder.Host.UseAgileConfig与SkyWalking不兼容 builder.Host.UseAgileConfig()与SkyWalking不兼容 Oct 12, 2022
@kklldog
Copy link
Collaborator

kklldog commented Oct 12, 2022

      public static IHostBuilder UseAgileConfig(this IHostBuilder builder, Action<ConfigChangedArg> e = null)
        {
            builder.ConfigureAppConfiguration((_, cfb) =>
            {
                cfb.AddAgileConfig(e);
            })
            .ConfigureServices((ctx, services) =>
            {
                services.AddAgileConfig();
            });

            return builder;
        }

UseAgileConfig 本质上就是调用了 ConfigureAppConfiguration 的 AddAgileConfig 方法,就是多了 services.AddAgileConfig(); 一步而已 。问题可能出在这。
方便把你的 program.cs 的代码贴出来看看吗?

@gudieaofei
Copy link
Author

`Environment.SetEnvironmentVariable("ASPNETCORE_HOSTINGSTARTUPASSEMBLIES", "SkyAPM.Agent.AspNetCore");

var builder = WebApplication.CreateBuilder(args);
builder.Host.UseAgileConfig();`

很简单的代码,引入SkyWalking的环境变量后,执行到UseAgileConfig那里就抛异常了

@kklldog
Copy link
Collaborator

kklldog commented Oct 13, 2022

那我得查一下 skyamp 的 client 有啥骚操作

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

2 participants