1

Mvvm Light と Ninject を使用した wpf アプリがあります。私のローカル マシンでは、RelayCommand は正常に動作します。アプリを別のサーバーに移動すると、メソッドが呼び出されなくなります (メッセージ ボックスはポップアップしません)。

MainViewModel.cs には

public ICommand GoClickCommand
{
    get
    {
        return new RelayCommand(() => MessageBox.Show("Directly in property!"), () => true);
    }
}

私が持っている MainWindow.xaml で

        `<Button Content="Go" HorizontalAlignment="Left" Margin="508,54,0,0" VerticalAlignment="Top" Width="75"
                Command="{Binding GoClickCommand}" IsDefault="True" Click="btn_go_Click"/>`

ボタンがクリックされたときに呼び出されるコード ビハインド コール btn_go_click にメソッドがあります。これは、ボタンが実際に機能することを確認するためのものです。それがNinjectと関係があるかどうかはわかりません。アプリを自己完結型 (1 つの .exe ファイルのみ) にしようとしているので、不足しているアセンブリを解決するコードが App.xaml.cs ファイルに含まれています。このコードなしでアプリを実行しようとしましたが、アプリに必要なアセンブリは GalaSoft.MvvmLight.WPF.dll と Ninject.dll の 2 つだけです。コードをコメントアウトし、これら 2 つのアセンブリをアプリと同じフォルダーに配置しましたが、RelayCommand はまだ起動していません。実際のアプリのコードはもっと複雑です。GoClickCommand プロパティのコードを変更して、何が問題なのかを突き止めました。助けやアドバイスをありがとう。

//from http://www.paulrohde.com/merging-a-wpf-application-into-a-single-exe/
        {
            AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
            App.Main();
        }

        private static Assembly OnResolveAssembly(object sender, ResolveEventArgs e)
        {
            var thisAssembly = Assembly.GetExecutingAssembly();

            //Get the name of the AssemblyFile
            var assemblyName = new AssemblyName(e.Name);
            var dllName = assemblyName.Name + ".dll";

            //Load from Embedded Resources - This function is not called if the Assembly is already
            //in the same folder as the app.
            var resources = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(dllName));
            var resourcesEnumerated = resources as string[] ?? resources.ToArray();
            if (resourcesEnumerated.Any())
            {
                //99% of cases will only have one matching item, but if you don't,
                //you will have to change the logic to handle those cases.
                var resourceName = resourcesEnumerated.First();
                using (var stream = thisAssembly.GetManifestResourceStream(resourceName))
                {
                    if (stream == null) return null;
                    var block = new byte[stream.Length];

                    //Safely try to load the assembly
                    try
                    {
                        stream.Read(block, 0, block.Length);
                        return Assembly.Load(block);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    catch (BadImageFormatException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            //in the case where the resource doesn't exist, return null.
            return null;
        }
    }
4

0 に答える 0