microsoft / MixedReality-WebRTC

MixedReality-WebRTC is a collection of components to help mixed reality app developers integrate audio and video real-time communication into their application and improve their collaborative experience
https://microsoft.github.io/MixedReality-WebRTC/
MIT License
908 stars 282 forks source link

Dependency to mrwebrtc.dll not working properly for .Net Framework 4.6.2 #531

Open mothermetabot opened 4 years ago

mothermetabot commented 4 years ago

Describe the bug Consuming the MixedReality.WebRTC library throws an error:

Unable to load DLL 'mrwebrtc': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

To Reproduce Steps to reproduce the behavior:

  1. Create WPF project. (.Net Framework 4.6.2)
  2. Add any code consuming the library (e.g. var deviceList = await DeviceVideoTrackSource.GetCaptureDevicesAsync();)
  3. Build and Run

Expected behavior The code is supposed to execute without errors.

Environment

Additional context I installed the Nuget package through Visual Studio 2019 Community. The project builds but fails immediately when I call a function from the WebRTC API. I cannot find any mrwebrtc.dll in the bin folder, is this normal behavior(see Exception Message above)? In the Solution Explorer, I can see Microsoft.MixedReality.WebRTC library under References and the respective DLL in the bin folder.

StackTrace:

   at Microsoft.MixedReality.WebRTC.Interop.DeviceVideoTrackSourceInterop.EnumVideoCaptureDevicesAsync(VideoCaptureDeviceEnumCallback enumCallback, IntPtr userData, VideoCaptureDeviceEnumCompletedCallback completedCallback, IntPtr completedUserData)
   at Microsoft.MixedReality.WebRTC.DeviceVideoTrackSource.<>c.<GetCaptureDevicesAsync>b__2_0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at SDHub.Gui.CallApp.CallView.<Button_Click>d__7.MoveNext() in C:\Users\esguio\Documents\Projects\SDHub\SDHub.Gui.CallApp\CallView.xaml.cs:line 52
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
   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, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   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.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at SDHub.Gui.CallApp.App.Main()
djee-ms commented 4 years ago

@mothermetabot I downloaded the NuGet package manually and I confirm that mrwebrtc.dll is in runtimes\win10-x86\native, so should be automatically deployed. I am not sure why it is not. Can you please confirm by manually copying the DLL next to your executable, to see if that solves things?

@efsjouw the bug report mentions x86 Desktop.

parad74 commented 4 years ago

System.DllNotFoundException: mrwebrtc assembly: type: member:(null) at Microsoft.MixedReality.WebRTC.DeviceVideoTrackSource.<>c.b__2_0() at System.Threading.Tasks.Task1[[System.Collections.Generic.IReadOnlyList1[[Microsoft.MixedReality.WebRTC.VideoCaptureDevice, Microsoft.MixedReality.WebRTC, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].InnerInvoke()

Thanks for your work.

I have already tried to use it several times, but bumped into mrwebrtc.dll Could you tell me where dll is looking for?

djee-ms commented 4 years ago

This is the general Windows rule of LoadLibrary(), which is invoked automatically by P/Invoke. Generally this means mrwebrtc.dll needs to be in the same folder as Microsoft.MixedReality.WebRTC.dll (the C# assembly).

srinath999 commented 3 years ago

Is there any possibility of using this for .net core web applications hosted on Linux platforms?

HaleXie commented 2 years ago

This is the general Windows rule of LoadLibrary(), which is invoked automatically by P/Invoke. Generally this means mrwebrtc.dll needs to be in the same folder as Microsoft.MixedReality.WebRTC.dll (the C# assembly).

I think this fixes the issue. I I copied Microsoft.MixedReality.WebRTC.2.0.2\runtimes\win10-x86\native\mrwebrtc.dll to the build output directory. It works for me

paulio commented 2 years ago

By default a console App will have a 'Any CPU' configuration. This confuses the package manager because it has x86 & x64 runtimes so doesn't copy over the runtime correctly. If you create a new configuration, say x64, then it should automatically work.