简体   繁体   English

使用COM的配置文件

[英]Configuration files with COM

I have an old PowerBuilder application that we are slowly phasing out. 我有一个旧的PowerBuilder应用程序,我们正在逐步淘汰它。 We are also moving to a more service orientated. 我们也正在朝着更加面向服务的方向发展。 So in order to facilitate this we are using C# COM wrappers to call WCF methods so old direct SQL calls can be slowly removed. 因此,为了简化此操作,我们使用C#COM包装器来调用WCF方法,以便可以慢慢删除旧的直接SQL调用。 We also use the C# COM wrappers when need functionality is needed in the power builder application. 在Power Builder应用程序中需要功能时,我们也会使用C#COM包装器。

Since we are using COM calls to DLL from PowerBuilder to C#, there is no need for an external executable. 由于我们使用的是从PowerBuilder到C#的DLL的COM调用,因此不需要外部可执行文件。 This means that a app.config file will not be loaded on its own. 这意味着app.config文件将不会单独加载。 At least that is what I noticed. 至少那是我注意到的。 Example: Let's say the main DLL that has the wrapper methods is Wrapper.dll. 示例:假设具有包装方法的主要DLL是Wrapper.dll。 If I had config named Wrapper.dll.config it would not get loaded when the make my call from PowerBuilder to C#. 如果我有名为Wrapper.dll.config的配置,则在从PowerBuilder调用C#时不会加载该配置。

The reason I would like to use a config file is because I would like to start using log4net in the C# dlls in order to make debugging easier because it is hard enough with PowerBuilder. 我之所以要使用配置文件,是因为我想开始在C#dll中使用log4net,以便使调试更加容易,因为PowerBuilder很难做到这一点。 There are other reasons that I would like to load configuration files but the easiest to explain is basically it is easier to set up some stuff using a config file. 我想加载配置文件还有其他原因,但最容易解释的是,使用配置文件来设置某些内容更容易。

So is there a way to load a configuration files into the Configuration manager for a COM call? 那么有没有办法将配置文件加载到COM调用的配置管理器中?

Thanks Tony 谢谢托尼

Check out this code from Mike Woodring . Mike Woodring查看此代码 I think it will enable you to do what you want. 我认为它将使您能够做自己想做的事。

Nice snippet JP. JP的摘要。

By default, Runtime assemblies actually get their config settings from the calling executable's config file. 默认情况下,运行时程序集实际上从调用可执行文件的配置文件中获取其配置设置。 Your snippet allows the loading of one associated with the actually library assembly. 您的代码段允许加载与实际库程序集关联的代码段。

Thanks for the answers, while helpful it was not what I was looking for. 感谢您的回答,尽管有帮助,但这不是我想要的。 The "easiest" to do what I need is to name the config file after the calling applications exe. 我需要做的“最简单”的操作是在调用应用程序exe之后命名配置文件。 So if the application's name is test.exe and your C# dll is wrapper.dll, then you would name the config file test.exe.config. 因此,如果应用程序的名称是test.exe,而您的C#dll是wrapper.dll,那么您将命名配置文件test.exe.config。 Since test.exe in this case is a PowerBuilder application, I can get away with this for now. 由于在这种情况下,test.exe是一个PowerBuilder应用程序,所以我现在就可以摆脱它。 If it were a .net app (and probably others) it would probably already have a config and thus get in the way. 如果它是一个.net应用程序(可能还有其他应用程序),则它可能已经具有配置,因此成为障碍。

Tony. 托尼

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM