I have created a dll following AaronReynoldsUK / PJSIP-PJSUA2-CSharp & used it in my WPF application. which was built and worked as expected. after, I published it(tried Msix packaging/ClickOnce/folder) It ran fine on my pc but after I send it to other Windows pcs, It failed to start on some windows regardless of their versions. checked all the framework dependencies & installed it on those pcs, The issue remained unchanged. when I checked their windows event viewer, I found the following error(summarized),

enter image description here

System.DllNotFoundException: Unable to load DLL 'pjsua2' or one of its dependencies: The specified module could not be found. (0x8007007E)

This error is only visible on the PCs where The App failed to build.

FYI: I am calling all the methods code-behind. Project is built targetting x86 and compiled & published using x86. Also, In the project reference, assembly Copy Local was True.

Please, feel free to ask if you need any more info or to give any suggestions.

Full Error Details:

Provider: .Net Runtime

    CoreCLR Version: 6.0.1322.58009
   .NET Version: 6.0.13
    Description: The process was terminated due to an unhandled exception.
    Exception Info: System.Windows.Markup.XamlParseException: 'The invocation of the constructor on type 'MYAPP.Views.Container' that matches the specified binding constraints threw an exception.' Line number '10' and line position '5'.
    ---> System.TypeInitializationException: The type initializer for 'MYAPP.Services.SIPServices.Sip.SipManager' threw an exception.
    ---> System.TypeInitializationException: The type initializer for 'pjsua2PINVOKE' threw an exception.
    ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception.
    ---> System.DllNotFoundException: Unable to load DLL 'pjsua2' or one of its dependencies: The specified module could not be found. (0x8007007E)
    at pjsua2PINVOKE.SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_pjsua2(ExceptionDelegate applicationDelegate, ExceptionDelegate arithmeticDelegate, ExceptionDelegate divideByZeroDelegate, ExceptionDelegate indexOutOfRangeDelegate, ExceptionDelegate invalidCastDelegate, ExceptionDelegate invalidOperationDelegate, ExceptionDelegate ioDelegate, ExceptionDelegate nullReferenceDelegate, ExceptionDelegate outOfMemoryDelegate, ExceptionDelegate overflowDelegate, ExceptionDelegate systemExceptionDelegate)
    at pjsua2PINVOKE.SWIGExceptionHelper..cctor() in E:\rnd23Jan\MYAPP\MYAPP\Services\SIPServices\Classes\pjsua2PINVOKE.cs:line 104
   --- End of inner exception stack trace ---
    at pjsua2PINVOKE.SWIGExceptionHelper..ctor()
    at pjsua2PINVOKE..cctor() in E:\rnd23Jan\MYAPP\MYAPP\Services\SIPServices\Classes\pjsua2PINVOKE.cs:line 124
   --- End of inner exception stack trace ---
    at pjsua2PINVOKE.new_Endpoint()
    at Endpoint..ctor() in E:\rnd23Jan\MYAPP\MYAPP\Services\SIPServices\Classes\Endpoint.cs:line 52
    at MYAPP.Services.SIPServices.Sip.SipManager..cctor() in E:\rnd23Jan\MYAPP\MYAPP\Services\SIPServices\Sip\SipManager.cs:line 26
   --- End of inner exception stack trace ---
    at MYAPP.Services.SIPServices.Sip.SipManager..ctor(EpConfig config, pjsip_transport_type_e tType) in E:\rnd23Jan\MYAPP\MYAPP\Services\SIPServices\Sip\SipManager.cs:line 72
    at MYAPP.Services.PjServices.Sip.SipSingletone..ctor() in E:\rnd23Jan\MYAPP\MYAPP\Services\PjServices\Sip\SipSingletone.cs:line 14
    at MYAPP.Services.PjServices.Sip.SipSingletone.get_GetSipInstance() in E:\rnd23Jan\MYAPP\MYAPP\Services\PjServices\Sip\SipSingletone.cs:line 23
    at MYAPP.Views.Container..ctor() in E:\rnd23Jan\MYAPP\MYAPP\Views\Container.xaml.cs:line 56
    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   --- End of inner exception stack trace ---
    at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
    at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
    at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
    at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
    at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
    at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
    at System.Windows.Application.DoStartup()
    at System.Windows.Application.<.ctor>b__1_0(Object unused)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
    at System.Windows.Threading.DispatcherOperation.InvokeImpl()
    at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
    at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Windows.Threading.DispatcherOperation.Invoke()
    at System.Windows.Threading.Dispatcher.ProcessQueue()
    at System.Windows.Threading.Dispatcher.WndProcHook(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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
    at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(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.Threading.Dispatcher.Run()
    at System.Windows.Application.RunDispatcher(Object ignore)
    at System.Windows.Application.RunInternal(Window window)
    at System.Windows.Application.Run()
    at MYAPP.App.Main()    

Provider: Application Error

    Faulting application name: MyApp.exe, version: 1.0.0.0, time stamp: 0x6387d16c
    Faulting module name: KERNELBASE.dll, version: 10.0.19041.572, time stamp: 0x979ddb1d
    Exception code: 0xe0434352
    Fault offset: 0x00129ab2
    Faulting process id: 0xb8c
    Faulting application start time: 0x01d92f1948c04dcc
    Faulting application path: C:\Users\TestVm\Desktop\net6.0-windows10.0.22621.0\MyApp.exe
    Faulting module path: C:\Windows\System32\KERNELBASE.dll
    Report Id: 88fd7660-b834-434b-8b37-58626cb7408b
    Faulting package full name: 
    Faulting package-relative application ID:    
 
1

There are 1 best solutions below

0
On BEST ANSWER

Thank you everyone for contributing to this issue. It was a really big help. However, this helped me export specific DLLs & referencing thus solving the problem.

Also, In the C++ project properties I had to Change "Copy to Output Directory" for all the project dependencies.