开发者

COM+ component not reading configuration from static context

I have 2 COM+ applications built in C#. They need access to a configuration, so in order to get them that (since they are in a server context) I set the Application Root Directory in the COM+ application to be a directory that contains an application.manifest and application.config file. The first component I built this way works. The second component, which I cannot find a single meaningful difference in the way I wrote it, does not.

If you try to access the configuration using ConfigurationManager.GetSection("unity") from a static context, it will return null. Calling the same thing from a non-static context produces the expected results (the section is returned). Since the first component works correctly calling that from a static context, what am I doing wrong?

Works in 开发者_JAVA技巧DLL 1, but not in DLL 2:

private static IUnityContainer m_unityContainer = new UnityContainer().LoadConfiguration()

Works in DLL 2:

private IUnityContainer m_unityContainer = new UnityContainer().LoadConfiguration()

or

private IUnityContainer m_unityContainer; public void Process() { m_unityContainer = new UnityContainer().LoadConfiguration(); }


Had a similar problem reading the config file in my COM+ assembly.

What worked for me:

1) BOTH the application.config file and application.manifest need to be in the same folder as the assembly (in my case debug folder).

2) The Application Root Directory needs to be specified in the Activation Tab of the COM+ Application. Run Component Services, right click Properties, go to Activation tab. Can also do this using regsvcs /appdir: option.


I'm not sure, but I think this had something to do with the differences in x64 and x86. I solved it by changing the code to

private static readonly Lazy<IUnityContainer> m_unityContainer = new Lazy<IUnityContainer>(() => new UnityContainer().LoadConfiguration());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜