为interop com对象设置app.config文件的位置 [英] Set location of app.config file for interop com object

查看:113
本文介绍了为interop com对象设置app.config文件的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS2010和VB.net(interop)中创建一个windows com对象

I am creating a windows com object in VS2010 and VB.net (interop)

这个com对象应该能够使用任何NON托管代码应用程序字,Excel或在这种情况下访问。

This com object should be able to work with any NON managed code application such as word, Excel or in this case Access.

创建com对象和使用regasm等工作正常。没有问题。

The creating of the com object and using regasm etc. works fine. No problem.

但是,INSTANT我创建一个com对象,需要连接字符串或任何其他app.config文件,然后它失败。在这种情况下,它恰好是一个Web服务,并且找不到公共端点或app.config文件错误。 (如果它只是一个连接字符串,我只是读取这个值 - 但配置文件相当混乱,由于web服务定义)。

However the INSTANT I create a com object that requires connection strings or anything else from the app.config file then it fails. In this case it happens to be a web service and the common "endpoint" or app.config file could not be found error occurs. (if it was just a connection string I would simply read in this value – but the config file quite messy due to a web service definition).

有一些建议将.dll和app.config放在SAME目录中作为office程序,如excel,然后将配置文件重命名为Excel.exe.config应该工作。

There is some suggesting that placing the .dll's and app.config in the SAME directory as the office program such as excel then renaming the config file as Excel.exe.config should work.

似乎没有为我工作。

有一种方法来拥有vb.net类(.dll),现在是一个com对象知道加载+使用一个配置文件为.dll而不是一些主应用程序文件?

Is there a means to have the vb.net class (.dll) that is now a com object to know to load + use a config file for the .dll and not some main application file?

注意,在这种情况下,我没有一个主应用程序配置文件,因为我启动一个非托管应用程序喜欢word或Excel并尝试使用我的类对象。

Note that in this case I do NOT have a main application config file since I am launching a non managed application like word or Excel and attempting to use my class object.

在vb.net显然,我可以将配置文件的东西从.dll复制到主应用程序配置和我们都要参加比赛。我没有一个托管的main文件,如下所示。

In vb.net obviously I can copy the config file stuff from the .dll to the main application config and we are off to the races. I don't have a managed "main" file as noted.

那么如何获取class.dll文件加载class.dll.config文件在非托管代码中创建对象的实例?

So how do I get the class.dll file to load up the class.dll.config file when an instance of the object is created in non managed code?

推荐答案

在类库中使用应用程序设置通常是一个糟糕的做法,.NET只支持它们用于EXE项目。它是一个[ComVisible] DLL的情况下的图表,你完全不能控制哪个EXE使用你的代码。

Using application settings in a class library is in general a poor practice, .NET only supports them for EXE projects. It is off the chart in the case of a [ComVisible] DLL, you have completely no control over which EXE uses your code.

这不是不工作,将foo.exe.config的副本放在foo.exe客户端目录中的工作很好。当您不是寻找此解决方案的唯一一个时,麻烦开始。现在安装程序开始覆盖彼此的.config文件,当加载项失败时,客户会失去大的时间。

It's not like it doesn't work, putting a copy of foo.exe.config in the foo.exe client directory works just fine. Trouble starts when you are not the only one that looked for this solution. Now installers start to overwrite each other's .config files, your customer loses big time when add-ins fail undiagnosably.

这个问题只有一个解决方案:不要使用设置。很多其他方法来提供配置到类库。在众所周知的位置的一个.xml文件也很好。

There's just one solution to this problem: don't use settings. Plenty of other ways to provide config to a class library. An .xml file in a well known location works just fine as well.

这篇关于为interop com对象设置app.config文件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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