0

私は2つのアプリを持っています。それらは共通の機能とアドオンを共有します。互換性を保つために、両方が同じ名前空間構造を使用しています。アプリはアドオンを cs としてロードし、それらを dll にコンパイルします。

cs と同じアドオンが両方のアプリで機能します - ソースからロードされ、dll にコンパイルされます。次回の実行時に、アプリは dll ファイルのみを読み込みます。

ソースコードなしで、アドオンを dll としてのみ配布できるようにしたいと考えています。問題は、dll が最初のアプリからコンパイルされた場合、2 番目のアプリからロードできないことです。

下の画像では、各アプリから個別にコンパイルされた「Adaptable MACD」があります。

マニフェストの比較 最初のアプリを 2 つ目のアプリから読み込もうとすると、次のエラー メッセージが表示されます。

"要求されたタイプの 1 つ以上をロードできません。詳細については、LoaderExceptions プロパティを取得してください。 "

これは私のコードです:

public void LoadDllIndicator(string dllPath, out string errorMessages)
{
    errorMessages = string.Empty;
    Assembly assembly = Assembly.LoadFrom(dllPath);
    try
    {
        Type[] types = assembly.GetTypes();

        foreach (Type type in types)
        {
            if (!typeof (IIndicator).IsAssignableFrom(type))
                continue;

            var newIndicator = Activator.CreateInstance(type) as Indicator;

            if (newIndicator == null)
            {
                errorMessages = "Cannot load: " + dllPath;
                return;
            }

            newIndicator.Initialize(SlotTypes.NotDefined);
            newIndicator.CustomIndicator = true;
            newIndicator.LoaddedFromDll = true;
            IntegrateIndicator(dllPath, out errorMessages, newIndicator);
        }
    }
    catch (Exception exception)
    {
        errorMessages = "ERROR: Loading '" + Path.GetFileName(dllPath) + "': " + exception.Message;
        if (exception.InnerException != null && !string.IsNullOrEmpty(exception.InnerException.Message))
            errorMessages += " " + exception.InnerException.Message;
    }
}

アプリの1つからコンパイルされたdllを他のアプリで動作させるにはどうすればよいですか?

4

0 に答える 0