他のライブラリ (DLL) をロードするコンソール アプリケーションがあります。私はSpring.NETを使用しています。私のコンソール アプリケーションは非常に単純です。選択したライブラリを初期化するために、DI を介して構成された app.config を読み込みます。
コード
ContextRegistry.GetContext();
構成 (app.config)
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context"
type="Spring.Context.Support.ContextHandler, Spring.Core"/>
<section name="objects"
type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="config://spring/objects"/>
<resource uri="assembly://MyDLL/MyDLL.Config/Services.xml"/>
</context>
<objects xmlns="http://www.springframework.net"
xmlns:aop="http://www.springframework.net/aop">
</objects>
</spring>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup></configuration>
各ライブラリには独自の「services.xml」ファイルがあります。これらのライブラリも Spring.NET を使用します。
<objects xmlns="http://www.springframework.net"
xmlns:aop="http://www.springframework.net/aop">
<object id="componentObj"
type="MyDLL.Services.ComponentService, MyDLL"
singleton="true" />
<object
id="componentServiceHost"
type="Spring.ServiceModel.Activation.ServiceHostFactoryObject, Spring.Services">
<property name="TargetName"
value="componentObj" />
</object>
</objects>
「StackOverflowException によりプロセスが終了しました。」という例外を取得します。をコメントアウトする<object id="componentServiceHost"
と、例外は発生しません。
デバッグ中の VS コンソールが表示されます
タイプ 'System.InvalidOperationException' の初回例外が System.ServiceModel.dll で発生しました
タイプ 'Spring.Objects.Factory.ObjectCreationException' の初回例外が Spring.Core.dll で発生しました
タイプ 'Spring.Objects.Factory.ObjectCreationException' の初回例外が Spring.Core.dll で発生しました
Managed (v4.0.30319)' はコード -2147023895 (0x800703e9) で終了しました。