I''ve fully and detailed described problem and question in this topic System.NullReferenceException in AppServiceResponse and System.BadImageFormatException of UWP with WPF desktop bridge package, but still have no found answer, what can cause this failure.
Topic link to Windows Dev Center above describes assembly, shows all used code with examples, including attempts to fix problem, and other details. So I will put only basic part of task in this stackoverflow topic to avoid text overload in post and focus only on System.BadImageFormatException, which provokes App.Connection null in Windows Application Package Project with connection from UWP to WPF application, created according to UWP with Desktop Extension – Part 3 lesson, (sending of request to desktop extension, read registry key values, and sending of request from desktop extension to UWP, handle requests from desktop code).
I've tried fix it different ways (also described above), but can't find any clue of reason, at least to know where to look for problem, maybe I've missed something, but I can't find related useful answers anywhere in internet
This is the message, but the System.Runtime.WindowsRuntime.dll is already in references:
System.BadImageFormatException HResult=0x80131058 Message=Could
not load file or assembly 'System.Runtime.WindowsRuntime,
Version=4.0.10.0, Culture=neutral, PublicKeyToken=...' or
one of its dependencies. Reference assemblies should not be loaded for
execution. They can only be loaded in the Reflection-only loader
context. (Exception from HRESULT: 0x80131058) Source=WpfApp1
StackTrace: at
WpfApp1.MainWindow.d__4.MoveNext() in
C:\Users\User\Desktop\UWP\App\WpfApp1\MainWindow.xaml.cs:line
58 at
System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine](TStateMachine&
stateMachine) at
WpfApp1.MainWindow.InitializeAppServiceConnection() at
WpfApp1.MainWindow..ctor() in
C:\Users\User\Desktop\UWP\App\WpfApp1\MainWindow.xaml.cs:line
37 Inner Exception 1: BadImageFormatException: Cannot load a reference
assembly for execution.
Any advice, guide or example would be very helpful
EDIT 1: **************************************************************************************************
I've tried all this combinations below two ways Debug and Release, as well as changed Solution platform "compiler settings", from menu bar of VS target from “Any CPU” to “X86 ” and vice-versa as shown in System.BadImageFormatException: Could not load file or assembly [duplicate], and from Solution->Properties->Configuration Properties->Configuration->Project contexts as well as from Project->Properties->Build->Platform target, but functionality and failure equally occurs in all cases:
Current Configuration Properties:
Console Launcher - AnyCPU
UWP - x86
Package - x86
WPF - AnyCPU
WinForms - AnyCPU
Setup all Solution apps to x86:
Console Launcher - x86
UWP - x86
Package - x86
WPF - x86
WinForms - x86
or x64:
Console Launcher - x64
UWP - x64
Package - x64
WPF - x64
WinForms - x64
executes same results by scenario:
Lessons Part 1 "Run WinForms from UWP" and Part 2 "Passing parameters" works successfully, runs application, sends parameters with loading of WPF or WinForms.
Scenarios from lesson Part 3 results with same failure, InitializeAppServiceConnection(); throws System.BadImageFormatException with direct debug, attempt to run WPF or WinForms from UWP, does nothing with requested application, just shows Console Launcher for a second, without any message, and Invoke desktop code to read reg key throws same System.NullReferenceException
Setup all apps to AnyCPU, except UWP, which bin debug output path, as platform targets drop-down menu from solution or app properties includes only x64, x86, ARM, ARM64:
Console Launcher - AnyCPU
UWP - x86
Package - AnyCPU
WPF - AnyCPU
WinForms - AnyCPU
throws:
Severity Code Description Project File Line Suppression State
Error MSB3270 There was a mismatch between the processor architecture
of the project being built "x86" and the processor architecture of the
reference
"C:\Users\User\Desktop\UWP_BD\UWP_BD\Launcher\bin\Debug\Launcher.exe",
"AMD64". This mismatch may cause runtime failures. Please consider
changing the targeted processor architecture of your project through
the Configuration Manager so as to align the processor architectures
between your project and references, or take a dependency on
references with a processor architecture that matches the targeted
processor architecture of your project. Package C:\Program Files
(x86)\Microsoft Visual
Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2106
and:
Severity Code Description Project File Line Suppression State
Warning The element 'PropertyGroup' in namespace
'http://schemas.microsoft.com/developer/msbuild/2003' has invalid
child element 'WapProjPath' in namespace
'http://schemas.microsoft.com/developer/msbuild/2003'. List of
possible elements expected: 'Property, VisualStudioVersion,
MinimumVisualStudioVersion, AdditionalFileItemNames,
AllowUnsafeBlocks, AppConfigForCompiler, ApplicationIcon,
ApplicationRevision, ApplicationVersion, AppDesignerFolder,
AspNetConfiguration, AspNetCoreHostingModel, AspNetCoreModuleName,
AssemblyKeyContainerName, AssemblyKeyProviderName, AssemblyName,
AssemblyOriginatorKeyFile, AssemblyOriginatorKeyFileType,
AssemblyOriginatorKeyMode, AssemblyType, AutoGenerateBindingRedirects,
AutorunEnabled, BaseAddress, BootstrapperComponentsLocation,
BootstrapperComponentsUrl, BootstrapperEnabled, CharacterSet,
CheckForOverflowUnderflow, CLRSupport, UseDebugLibraries, CodePage,
Configuration, ConfigurationName, ConfigurationOverrideFile,
CreateDesktopShortcut, CreateWebPageOnPublish,
CurrentSolutionConfigurationContents, DebugSecurityZoneURL,
DebugSymbols, DebugType, DefaultClientScript, DefaultHTMLPageLayout,
DefaultTargetSchema, DefineConstants, DefineDebug, DefineTrace,
DelaySign, DisableLangXtns, DisallowUrlActivation,
CodeAnalysisAd.... Package C:\Users\User\Desktop\UWP_BD\UWP_BD\Package\Package.wapproj 49
and x64:
Console Launcher - AnyCPU
UWP - x64
Package - AnyCPU
WPF - AnyCPU
WinForms - AnyCPU
Severity Code Description Project File Line Suppression State
Error MSB3270 There was a mismatch between the processor architecture
of the project being built "MSIL" and the processor architecture of
the reference
"C:\Users\User\Desktop\UWP_BD\UWP_BD\UWP_Control\bin\x64\Debug\UWP_Control.exe",
"AMD64". This mismatch may cause runtime failures. Please consider
changing the targeted processor architecture of your project through
the Configuration Manager so as to align the processor architectures
between your project and references, or take a dependency on
references with a processor architecture that matches the targeted
processor architecture of your project. Package C:\Program Files
(x86)\Microsoft Visual
Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2106
I'm not sure, maybe I should change Minimum Version to Anniversary Edition or to Windows 10 (10.0; Build 10214) with creating of UWP which default is Windows 10 (10.0; Build 10586):
EDIT 2: **************************************************************************************************
I'm using Windows 10 Pro 64-bit OS, x64-basesd processor with Visual Studio 2019 Version 16.1.4, Target Framework: .NET Framework 4.7.2 Version 4.7.03056, Microsoft.NETCore.Universal Windows Platform 6.2.8 Path folder C:\Program Files (x86)\Microsoft SDKs\Windows includes folders: v7.0A, v8.1, v8.1A, v10.0A
in .csproj:
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.14393.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.14393.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
I got the same failure System.BadImageFormatException, if I change Minimum Version to Windows 10 Anniversary Edition (10.0; Build 14393) same as for Target Version, with both previous and new assembly without Part 1 and Part 2 code.
Also I've followed Roy Li suggestion in System.NullReferenceException in AppServiceResponse and System.BadImageFormatException of UWP with WPF desktop bridge package on Windows Dev Center, "To create a more simple demo to reproduce the problem". So, I've created new package only with UWP and WPF according only UWP with Desktop Extension – Part 3 with UWP_FullTrust_3.
In previous assembly I have missed SingleInstance.cs in WPF application, but including of this code into previous or new assembly (without "Running app" and "passing parameter"), throws error:
Severity Code Description Project File Line Suppression State
Error CS0017 Program has more than one entry point defined. Compile
with /main to specify the type that contains the entry
point. FullTrust C:\Users\User\Desktop\UWP_BD2\Solution1\FullTrust\SingleInstance.cs 57 Active
on this part of code:
[STAThread]
public static void Main(string[] args)
{
SingleInstanceManager manager = new SingleInstanceManager();
manager.Run(args);
}
EDIT 3: **************************************************************************************************
So, for Windows 10 Pro 64-bit OS, Version 1803 (OS Build 17134.829) suitable Target version should be 17134, I'm not sure about Minimum version:
I've updated Windows just few hours ago. Something goes wrong in Targets menu with creating Windows Application Package Project, or UWP, which does not contains 17134, with higher version, I got this message:
By some reason Target selection menu does not contains 17134 and it is gone for Windows Application Package Project too:
EDIT 4: **************************************************************************************************
I've installed SDK version 17134, and selected 17134 for Target Version with Windows Application Package Project and UWP creation.
I've added code, references, setup, but I got same Error! I'm not sure if I am able to fix it. Maybe complete test project, with actual code will help.
So, here is a full Solution repository UWP_desktop_bridge. It is UWP and Console Launcher to WPF, based on Part 1, Part 2, Part 3 of UWP-FullTrust lesson by Stefan Wick MSFT
Without InitializeAppServiceConnection(); scenarios from Part 1, Part 2 works, but with including InitializeAppServiceConnection(); to WPF InitializeComponent(); to get Part 3 functionality, I got:
System.BadImageFormatException HResult=0x80131058 Message=Could
not load file or assembly 'System.Runtime.WindowsRuntime,
Version=4.0.10.0, Culture=neutral, PublicKeyToken=...' or
one of its dependencies. Reference assemblies should not be loaded for
execution. They can only be loaded in the Reflection-only loader
context. (Exception from HRESULT: 0x80131058) Source=WpfApp1
StackTrace: at
WpfApp1.MainWindow.d__4.MoveNext() in
C:\Users\User\Desktop\UWP_desktop-bridge\Solution1\WpfApp1\MainWindow.xaml.cs:line
59 at
System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine](TStateMachine&
stateMachine) at
WpfApp1.MainWindow.InitializeAppServiceConnection() at
WpfApp1.MainWindow..ctor() in
C:\Users\User\Desktop\UWP_desktop-bridge\Solution1\WpfApp1\MainWindow.xaml.cs:line
38 Inner Exception 1: BadImageFormatException: Cannot load a reference
assembly for execution.
and same with SingleInstance.cs if using of this part of code:
[STAThread]
public static void Main(string[] args)
{
SingleInstanceManager manager = new SingleInstanceManager();
manager.Run(args);
}
Severity Code Description Project File Line Suppression State Error
CS0017 Program has more than one entry point defined. Compile with
/main to specify the type that contains the entry point.
It is similar functionality and failure as in my previous projects.
EDIT 5: **************************************************************************************************
At this time, I've carefully created copy-paste build, based on ZhuMingHao/AppSerViceTest demo given in answer by Nico Zhu - MSFT on related question Send speech recognition args.Result as parameter in UWP desktop-bridge package:
Debug loads UWP and WPF successfully. With click on the Click button with in UWP AppSerViceTest/AppServiceTest/MainPage.xaml.cs:
I got same exception:
System.NullReferenceException: 'Object reference not set to an
instance of an object.
With click on WPF Send Message button, it is just closes WPF app, UWP StatusBlock and InfoBlock shows nothing.
Direct debug of WPF and click Send message button, throws a different content of the same System.BadImageFormatException:
System.BadImageFormatException HResult=0x80131058 Message=Could
not load file or assembly 'System.Runtime.WindowsRuntime,
Version=4.0.10.0, Culture=neutral, PublicKeyToken=...' or one of its
dependencies. Reference assemblies should not be loaded for execution.
They can only be loaded in the Reflection-only loader context.
(Exception from HRESULT: 0x80131058) Source=WpfApp1 StackTrace:
at WpfApp1.MainWindow.<Button_Click_1>d__5.MoveNext() in
C:\Users\User\Desktop\UWP\UWP_DB_SR\WpfApp1\MainWindow.xaml.cs:line
91 at
System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine](TStateMachine&
stateMachine) at WpfApp1.MainWindow.Button_Click_1(Object sender,
RoutedEventArgs e) 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.RaiseEvent(RoutedEventArgs e) at
System.Windows.Controls.Primitives.ButtonBase.OnClick() at
System.Windows.Controls.Button.OnClick() at
System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs
e) at System.Windows.UIElement.OnMouseLeftButtonUpThunk(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.ReRaiseEventAs(DependencyObject sender,
RoutedEventArgs args, RoutedEvent newEvent) at
System.Windows.UIElement.OnMouseUpThunk(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
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 WpfApp1.App.Main() Inner
Exception 1: BadImageFormatException: Cannot load a reference assembly
for execution.
SOLUTION: **************************************************************************************************
Solution answer given by Stefan Wick MSFT to question described also on WDC topic System.NullReferenceException in AppServiceResponse and System.BadImageFormatException of UWP with WPF desktop bridge package on System.BadImageFormatException with particular UWP desktop-bridge app communication project, based on UWP with Desktop Extension – Part 3 example UWP-FullTrust/UWP_FullTrust_3/ as well as solver my copy of Nico Zhu - MSFT solution ZhuMingHao/AppSerViceTest:
My incorrect:
Program Files (x86)\Reference
Assemblies\Microsoft\Framework.NETCore\v4.5.1\System.Runtime.WindowsRuntime.dll
Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
Must be correct references setup:
ProgramFiles(x86)%\Reference
Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
ProgramFiles(x86)%\Windows
Kits\10\UnionMetadata\10.0.17134.0\Windows.winmd
This exception occurs when referencing the Windows Runtime libraries incorrectly from the non-UWP project (WPF, Winforms, Console, etc.). Be sure to reference them as follows
In the "Add Reference …" dialog click "Browse …" and set the filter to "All Files (*.*)"
Navigate to "%ProgramFiles(x86)%\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll"
Navigate to "%ProgramFiles(x86)%\Windows Kits\10\UnionMetadata\{TargetVersion}\Windows.winmd"
I'm having some issues running the Emgu on my server. It runs fine locally, but when I try to use it on the server with IIS, it doesnt work.
Here is the error:
System.TypeInitializationException: The type initializer for 'Emgu.CV.CvInvoke' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'cvextern': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Emgu.CV.CvInvoke.RedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)\r\n at Emgu.CV.CvInvoke..cctor()
--- End of inner exception stack trace ---
at Emgu.CV.CvInvoke.cvCreateImageHeader(Size size, IplDepth depth, Int32 channels)
at Emgu.CV.Image`2.AllocateData(Int32 rows, Int32 cols, Int32 numberOfChannels)
at Emgu.CV.Image`2.set_Bitmap(Bitmap value)
at VerifyID.Managers.ImageTreatmentsManager.ExtractDocumentFromImage(Bitmap bitmap)
at VerifyID.VerifyWorker.ExecuteOCR(BigIdRequest request, BigIdEvent bigIdEvent)
I have the following dlls inside the x86 and x64:
concrt140.dll*
liblept172.dll*
msvcp140.dll*
vcruntime140.dll*
cvextern.dll*
libtesseract304.dll*
opencv_ffmpeg320.dll*
IIS version: 10.0
After copying the x64 dlls directly to the bin directory of the build the error changed to:
System.TypeInitializationException: The type initializer for 'Emgu.CV.CvInvoke' threw an exception. ---> System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at Emgu.CV.CvInvoke.RedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)
at Emgu.CV.CvInvoke..cctor()
--- End of inner exception stack trace ---
at Emgu.CV.CvInvoke.cvCreateImageHeader(Size size, IplDepth depth, Int32 channels)
at Emgu.CV.Image`2.AllocateData(Int32 rows, Int32 cols, Int32 numberOfChannels)
at Emgu.CV.Image`2.set_Bitmap(Bitmap value)
at VerifyID.Managers.ImageTreatmentsManager.ExtractDocumentFromImage(Bitmap bitmap)
at VerifyID.VerifyWorker.ExecuteOCR(BigIdRequest request, BigIdEvent bigIdEvent)
Could someone help ?
I had this same problem, the application works perfectly on the local server (IIS Express used by the Visual Studio) but not on the remote Windows server, the solution that worked for me was:
(Please test your application between each step, maybe you don't need to do them all)
In Visual Studio, open your application project properties and set the "Platform" to "Any CPU". Then publish your application to the remote server.
Move all .dll files inside the x86 folder to the bin folder, pay special attention to the cvextern.dll, it must be inside the bin folder side by side with your application dll.
Install Visual C++ Redistributable for Visual Studio on the remote server (just google it and you will find the download link. Please choose the download version according to your VS version, 2013, 2015, 2017, 2020, 2050...). Use the x86 installation even if you sever OS is x64.
Activate your app_pool for the application for running 32 bit. https://help.webcontrolcenter.com/kb/a1114/how-to-enable-32-bit-application-pool-iis-7-dedicatedvps.aspx
Go to the application \bin folder, grant the file security for the folder "x86" (which contains all the dll for emgu) as described in the following link "http://www.iis.net/learn/manage/configuring-security/application-pool-identities if your apppool being in used in defaulapppool, then you should add user "IIS AppPool\DefaultAppPool"
I really don't know why the x64 versions of those dlls are not working on the server for me. I still investigating it and as soon I find out why I will update this post.
Another solution (that is not elegant at all, but works) is to install the Visual Studio at the server, doing the same installation process that you have done for your development environment. By doing this you will have all dependencies and dlls needed (including the Visual C++) installed on the server.
Hope it helps!
we're seeing an intermittent problem when we try to run a .Net 4.0 application on a remote computer via PsExec.
The target computer is Windows Server 2008 SP2 64-bit with .Net 4.0 and .Net 4.5 installed.
I've been told that this has been happening here since .Net 4.5 was installed, but I'm new to the project, so I can't confirm that this is when the problem started happening.
The code that is failing is doing this:
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
return (ParameterData)config.GetSection("ParameterData");
Here's the stack trace:
System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) ---> System.Runtime.InteropServices.COMException: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
at System.Security.Policy.PEFileEvidenceFactory.GetLocationEvidence(SafePEFileHandle peFile, SecurityZone& zone, StringHandleOnStack retUrl)
at System.Security.Policy.PEFileEvidenceFactory.GenerateLocationEvidence()
at System.Security.Policy.PEFileEvidenceFactory.GenerateEvidence(Type evidenceType)
at System.Security.Policy.AssemblyEvidenceFactory.GenerateEvidence(Type evidenceType)
at System.Security.Policy.Evidence.GetHostEvidenceNoLock(Type type)
at System.Security.Policy.Evidence.GetHostEvidence(Type type, Boolean markDelayEvaluatedEvidenceUsed)
at System.Security.Policy.AppDomainEvidenceFactory.GenerateEvidence(Type evidenceType)
at System.Security.Policy.Evidence.GetHostEvidenceNoLock(Type type)
at System.Security.Policy.Evidence.RawEvidenceEnumerator.MoveNext()
at System.Security.Policy.Evidence.EvidenceEnumerator.MoveNext()
at System.Configuration.ClientConfigPaths.GetEvidenceInfo(AppDomain appDomain, String exePath, String& typeName)
at System.Configuration.ClientConfigPaths.GetTypeAndHashSuffix(AppDomain appDomain, String exePath)
at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigurationHost.get_ConfigPaths()
at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath)
at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
--- End of inner exception stack trace ---
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.Configuration..ctor(String locationSubPath, Type typeConfigHost, Object[] hostInitConfigurationParams)
at System.Configuration.ClientConfigurationHost.OpenExeConfiguration(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath)
at System.Configuration.ConfigurationManager.OpenExeConfigurationImpl(ConfigurationFileMap fileMap, Boolean isMachine, ConfigurationUserLevel userLevel, String exePath, Boolean preLoad)
at System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel userLevel)
This is executed during our automated test build deployment process. I've been able to boil it down to a simple executable that does the code above, and I call PsExec from my Windows 7 development machine, but the problem's intermittent.
It seems to occur more regularly if I wait several minutes between invocations of PsExec. I started looking at this problem today, and was able to repro it pretty regularly in the morning, but not very easily in the afternoon.
I also see warnings like this in the Event Log:
Windows detected your registry file is still in use by other applications or services. The file will be unloaded now. The applications or services that hold your registry file may not function properly afterwards.
DETAIL -
1 user registry handles leaked from \Registry\User\mySID:
Process 5568 () has opened key \REGISTRY\USER\mySID
I don't know how the Event Log errors are related to the exception, if at all.
The PsExec command line is: PsExec /accepteula \\myServerName -d "path_to_exe"
I'm wondering if it's a problem with the user profile service, so I was thinking about not loading the profile when calling PsExec, but since it's so intermittent, I'm not sure how I would know if I've fixed it.
Searching the internet shows that some people think it might be related to impersonation, but nothing that directly matches my situation.
Has anyone seen anything like this? This is really weird.
Thanks!
Phil
if it works when run locally but not when run remotely there's a possibility:
When using PsExec the programs on the remote machine are limited to 150MB of memory
Running this on the remote machine will allow remote commands to use more than 150 MB of memory:
set-item wsman:localhost\Shell\MaxMemoryPerShellMB 2048
I'm trying to start using emgu CV open CV for C#. But I'm having trouble making it work.
I'm following this guide to make simple program using emgu CV Link but I get following error: (any idea what I'm doing wrong?)
System.TypeInitializationException was unhandled
Message=The type initializer for 'Emgu.CV.CvInvoke' threw an exception.
Source=Emgu.CV
TypeName=Emgu.CV.CvInvoke
StackTrace:
at Emgu.CV.Image`2..ctor(String fileName) in c:\Emgu\emgucv-windows-x86-gpu 2.4.2.1777\Emgu.CV\Image.cs:line 144
at TEST.Form1.button1_Click(Object sender, EventArgs e) in c:\documents and settings\laci\my documents\visual studio 2010\Projects\TEST\TEST\Form1.cs:line 28
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TEST.Program.Main() in c:\documents and settings\laci\my documents\visual studio 2010\Projects\TEST\TEST\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.DllNotFoundException
Message=Unable to load DLL 'opencv_core242': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Source=Emgu.CV
TypeName=""
StackTrace:
at Emgu.CV.CvInvoke.cvRedirectError(CvErrorCallback errorHandler, IntPtr userdata, IntPtr prevUserdata)
at Emgu.CV.CvInvoke..cctor() in c:\Emgu\emgucv-windows-x86-gpu 2.4.2.1777\Emgu.CV\PInvoke\CvInvoke.cs:line 166
InnerException:
Since Emgu.CV is just a .NET wrapper (see http://en.wikipedia.org/wiki/Wrapper_library), you need to put the native .DLL files of OpenCV in your application output directory.
You can find the required files by downloading the corresponding version of OpenCV at http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.2/OpenCV-2.4.2.exe/download
I will save you all a lot of time.
for EMGU CV version 2.4.* the missing dll is "nvcuda.dll" which is not part of the Binaries of EMGU but its usually located in system32 folder (maybe you need to have nvidia driver installed, if not just look for the dll online)
You might solve this problem by Using Dependency Walker -> http://www.dependencywalker.com/ on "opencv_core242.dll" to find any missing DLLs.
For me, It show that I didn't has tbb.dll as Thread here tbb.dll not found
Just download from https://www.threadingbuildingblocks.org/ and copy tbb*.dll to working directory or "System32" it will be fine
Old one, but I had the same problem. Turns out that 2.4.0 has GPU integration and if you don't have an Nvidia card, nvcuda.dll is missing and opencv_core242.dll fails to load. Tried everything, the only solution was to go back to 2.3.0 and everything worked fine.
Exactly as the error states - it can't find the native DLL in the working directory of your applcation. Make sure the opencv_core242.dll library is copied to the output directory and working directory of your application.
Download dependency walker from http://www.dependencywalker.com/ and open the .dll claiming to not load. Then look for the dependencies, if one or more are missing from the directory of the app of even your system folder (system32 or syswow64) then they need to be in there.
here are proper steps to solve the problem.
visit : https://sourceforge.net/project/emgucv/emgucv/2.4.2/
download specific version of emgucv 2.4.2 according to your operating system like for windows x86 you can download : libemgucv-windows-x86-gpu-2.4.2.1777.exe
install it some where like C:\Emgu
after that go to C:\Emgu\emgucv-windows-x86-gpu 2.4.2.1777\bin\x86 and copy all opencv dll files and paste it in your application exe output directory.
to remove unnecessary opencv dll files you , run your application and then press ctrl+A and try to delete the files , those files which are used by your app you will not be able to delete as your app is running and they are in use and the reset unused dll files will be deleted , other than that you can use dependency walker app (http://www.dependencywalker.com/ ) which is outdated may or may not work
I am having a rather strange problem, I deployed 2 .NET applications on my machine. Both run on v2.0.
Now, while one of it works smoothly, the other one doesn't even start! Moreover, it doesn't throw any error, I couldn't see any error listings in the Event Viewer.
Becoming hard to debug. On every other machine, both the exe's work perfectly fine!
Any known issues?
EDIT:
I caught an Unhandled Exception and the exception is this;
System.Runtime.InteropServices.COMException (0x80040154): Class not registered(Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithoutLicense(Guid clsid)
at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
at System.Windows.Forms.AxHost.CreateInstance()
at System.Windows.Forms.AxHost.GetOcxCreate()
at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
at System.Windows.Forms.AxHost.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.AxHost.EndInit()
at BrowsingFiles.Form1.InitializeComponent()
at BrowsingFiles.Form1..ctor()
at BrowsingFiles.Program.Main(String[] args)
Thanks
You are calling a COM component that is not registered on that machine.
Ideally, your deployment project would register any COM dependencies: How To Register COM Objects in Visual Studio .NET: Steps to Register a COM Module in a Visual Studio .Net Deployment Project
One more solution apart from the one given by Mitch Wheat
Copy the DLL, in the System32 file at it's proper location and then using command prompt register the dll with the system using
regsvr32 location-of-the-dll
You can go to project -> add reference to add your com component. Make sure you have the com component loaded on this system. You can go and view the references on your previous machine and see where the references are located and modify this new machine accordingly.