0

I am on Windows 64bit working with Visual Studio 2015. I have this WPF project with its C++ backend and it uses several additional packages such as OpenCV, EmguCV and DevExpress.

Now if I run as Release, it compiles fine. Also if I go to the current directory via explorer and navigate to bin -> Release then execute the .exe file, it also runs fine.

Problem: The project does not work on any other machine: If I copy the whole Release folder and paste it onto another machine, and try to execute, it pops a "Could not load file or assembly" error. See Error Here and the full error below.

Insights: Those target machines used to be able to execute a Release just fine and the same way (Copy/Paste or Installer). The project targets .Net framework 4.5 and needs the 2013 + 2015 redistributable files. Everything is installed on the target machine. Also the Dlls that the error is mad about, exist physically in the Release folder. And when I build an installer (using Inno Setup) I see all the needed and existing Dlls being included (OpenCv stuff and DevExpress).

There are like 10 OpenCv Dlls that are not shown within "Solution Explorer -> References" but physically exist in the Release Folder (we pasted them their). Now, if I remove these files from MY Release Folder, I get the exact same error. On the other hand, if I paste them in THEIR Release Folder, the error persists.

The "Solution Explorer -> References -> Properties -> Local Copy" of all the files are set to true. I currently build as x86, because if I build as x64 I get this error:

Error NuGet Error: Unable to find version '2.4.8' of package 'OpenCV.overlay-x64_v120_Release'. C:\Users\bla\Desktop\bla\packages\OpenCV.2.4.8\build\native\OpenCV.targets

What could be the issue?

Complete Error:

Fatal @ 9/9/2016 9:18:19 AM - CurrentDomainOnUnhandledException v2.0.1.0 - Exception Info: System.Windows.Markup.XamlParseException: The invocation of the constructor on type 'bla.MainWindow' that matches the specified binding constraints threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'bla.bla.bla.dll' or one of its dependencies. The specified module could not be found.

at bla.MainWindow..ctor()

--- End of inner exception stack trace ---

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 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 bla.App.Main()

Khalil Khalaf
  • 9,259
  • 11
  • 62
  • 104
  • Try turning on the Fusion log -- http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx – J.H. Sep 09 '16 at 14:48
  • Did you turn on the Fusion log? – J.H. Sep 09 '16 at 15:52
  • @j.h I just started. Sorry for being late. I should execute fusion on the target machine and where the error is correct? Would you mind going to a chat room? – Khalil Khalaf Sep 09 '16 at 18:00
  • @FirstStep - Yes, the machine having the issue. I don't mind going to a chat room. – J.H. Sep 09 '16 at 18:01

2 Answers2

1

I found this link that may help you

I want a solution for this : Please make sure that the file is accessible and that it is a valid assembly or COM component

Marked answer is:

the file is a native DLL which means you can't add it to a .NET project via Add Reference... you can use it via DllImport (see http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx)

Community
  • 1
  • 1
  • Mohammed I still think it is something related to build, references, something need to be checked as true. It is how I used to do it since ever, for each release: I just build and copy paste the folder. I don't know what got messed recently so it is not working on the target machine anymore.. I don't want to take the hard coding road. What do you think? – Khalil Khalaf Sep 09 '16 at 15:14
0

Right click references in the project then re-add the assemplies for the OpenCV again, then refresh and re-build the solution. Also make sure that the project targets .Net framework 4.5 indeed, because sometimes the same errors appear if it targets .net client framework.

Hasson
  • 1,894
  • 1
  • 21
  • 25