C#COM组件无法加载到非托管C ++应用程序时读取配置 [英] C# COM Component Fails To Read Config When Loaded Into An Unmanaged C++ App

查看:168
本文介绍了C#COM组件无法加载到非托管C ++应用程序时读取配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C#编写的COM组件,它调用ConfigurationManager.AppSettings.Get(...)。此组件在非托管C ++应用程序中实例化。



每次ConfigurationManager.AppSettings无法读取配置文件。



可能有两个问题。



1)应用程序运行时应调用app.config(即C ++ exe的名称)。 config在结束,或者我的C#类库的名称与.config在末端)。



2)配置文件应该在哪里生活作为C#COM组件,或在与C ++ exe



相同的文件夹中我尝试过对ConfigurationManager.OpenExecConfiguration的所有调用;所有失败。



我想要的最好是,它只是工作没有代码更改。如果没有,明智的调用OpenExeConfiguration,所以我仍然可以使用ConfigurationManager.AppSettings.Get(...) / p>

这可能是冰山一角,因为我想在使用自定义配置部分的C#COM组件中使用log4net。



虽然我不介意通过配置对象更改自己的代码以使用访问设置,但我无法更改log4net代码。



任何人打这个吗?任何想法?

解决方案

如果运行procmon( http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx )当你的应用程序运行时你可以看到*。配置文件,它正在寻找?


I have a COM component written in C# that makes calls to ConfigurationManager.AppSettings.Get(...). This component is instantiated inside an unmanaged C++ application.

Every time, ConfigurationManager.AppSettings is unable to read the configuration file.

There might be two problems.

1) What should the app.config be called when the app is running (i.e. the name of the C++ exe with .config on the end, or the name of my C# class library with .config on the end).

2) Where should the config file live (i.e. in the same folder as the C# COM Component, or in the same folder as the C++ exe

I've tried various calls to ConfigurationManager.OpenExecConfiguration; all failed.

What I want ideally, is for it to just work with no code changes. Failing that, a judicious call of OpenExeConfiguration so that I can still use ConfigurationManager.AppSettings.Get(...)

This might be the tip of the iceberg because I'd like to use log4net in the C# COM Component which uses a custom config section.

Whilst I dont mind changing my own code to use access settings via a config object, I can't change the log4net code.

Anyone else hit this before? Any ideas?

解决方案

If you run procmon ( http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx ) while your app is running can you see the *.config file that it is looking for?

这篇关于C#COM组件无法加载到非托管C ++应用程序时读取配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆