私はこの問題を2日間グーグルで調べていますが、私が見たすべての解決策が私のシナリオに完全に適合していないか、修正が機能しません。
WPFデスクトップアプリケーションがあります。プロジェクトをデバッグしているときは、すべてが正常に機能しており、100%です。しかし、アプリをデプロイした瞬間(開発したPCでも)、クラッシュします。検出したファーストクラスのインスタンス化でクラッシュし、innerExceptionが常にnullreference例外である例外をスローするようです。ただし、TargetInvocationException、TypeInitializationExceptionなど、前者の例外は変化し続けます。
スタックトレースは次のとおりです。
System.TypeInitializationException: The type initializer for 'eTute.BusinessLayer' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at eTute.BusinessLayer..cctor()
--- End of inner exception stack trace ---
at eTute.BusinessLayer.EncryptPassword(String password)
at eTute.MainWindow.imgLock_MouseDown(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
「BusinessLayer」は私のデータアクセス層(DAL)のようなものです。最初はインスタンス駆動型でしたが、BusinessLayerのコンストラクターでクラッシュし始めたときに、クラス全体を静的に変更しました。これで、次のインスタンス化でクラッシュするようです。
注:インストーラーを作成するには、VisualStudioのセットアップウィザードを使用しました。アプリはSQLExpressデータベースを使用しますが、小さなインスタンスでクラッシュするため、使用することさえできません。
ヘルプやコメントをいただければ幸いです。私はこれまでインストールを行ったことがありませんが、これほど複雑であってはならないと感じています。
更新
この問題は、app.configファイルのconnectionStringsへのアクセスに関連しているようです。上記のコードをConfigurationManager.ConnectionStrings["name"].ConnectingString
ハードコードされた文字列変数に置き換えると、問題は解消されました。
しかし、アプリがデプロイされたときにapp.configファイルをどのように使用するのでしょうか。