(Environment = Windows 10 1803, program type is .exe)
I have written a program to be used across different computers at work, however, When i try to run the compile program from anyone elses machine other than my own (and my fellow IT coworkers), I end up with this error:
(From event viewer)
Event 1026, .NET Runtime Application: program123.exe Framework Version
v4.0.30.319 Description: The process was terminated due to an
unhandled exception. Exception Info: System.IO.FileNotFoundException
at
System.Reflection.RuntimeAssembly._nLoad(System.Reflection.AssemblyName,
System.String, System.Security.Policy.Evidence,
System.Reflection.RuntimeAssembly, ........
I have extensive logging in the application and pretty much log immediately upon program entry. However, my log never gets hit - (to me, this means that this application is being blocked, or dying before running any code).
This is different because my application does not even start. In the example that you recommended, the application begins and then fails on an event. My .exe will not work at all.
Any help would be appreciated. Thanks in advance.
Related
I'm trying to load a third-party DLL in a Console App project created in Visual Studio Community 2022. Environment is Windows 10. I have tried both .NET 5.0 and 6.0
No matter what I have tried, I get the error "Unhandled exception. System.BadImageFormatException: Bad IL format. The format of the file is invalid."
I have checked and normally this error is because I'm trying to load a x64 DLL in a x86 app or viceversa, but I know this is not the case because:
I have been able to load this specific DLL in C (using LoadLibrary() in Codeblocks) and JAVA (using JNA), configuring the applications for a x86 target platform. I have configured this console app for a x86 target platform as well in properties.
The DLL when loaded starts writing to a log file. The log file destination is fixed, and can't be deactivated. Whenever I run my app, I see the log being written to. I realized that the log was being written to by using Sysinternals' Process Monitor.
The log only says
INFO: 2.23.00 12:14:27(00000015) PCLService.cpp:138 [22.11.2021] logCreate
INFO: 2.23.00 12:14:27(00000000) PCLService.cpp:141 PDA_Manager: DllMain attached
INFO: 2.23.00 12:14:27(00000000) PCLService.cpp:145 PDA_Manager: DllMain detach
Normally, the detach should only happen when the DLL is unloaded/program is closed. Here it happens automatically. It is like the program can't keep the DLL loaded, giving the error message.
Here is my current code.
using System;
using System.Reflection;
namespace ConsoleApp5
{
internal class Program
{
static void Main(string[] args)
{
//var DLL = Assembly.LoadFile(#"C:\Documentacion\VisaNet\Proyectos\Simpler\bin\Debug\x86\PCLService.dll");
var DLL = Assembly.LoadFrom("PCLService.dll");
Console.ReadLine();
}
}
}
I have tried both LoadFrom() and LoadFile(). Even tried Load(), but the error is different about additional information that I don't know how to get.
I have checked Assembly Binding Log Viewer (fuslogvw.exe) and Process Monitor. I do not see any obvious problem.
I assume that whatever error happens, it did happen by the time of the last 4 entries about PCLService.log, which must the ones writing in the DLL log about detaching, because there are no more entries about the log in Process Monitor.
While I'm a experienced programmer, I'm totally new to Visual Studio / C#
Any assistance would be welcome.
To call a native dll, you have to use [DllImport] together with a function prototype. Any of the Assembly.LoadXXX() methods are for managed libraries only. Maybe Using a 32bit or 64bit dll in C# DllImport will help you.
My application randomly crashes on my target machines with an .net failure. In mscorelib.dll there seems to be a System.InvalidCastException.
The error occures in:
System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(System.Object, Boolean)
and the reason is:
Unable to cast object of type 'System.Threading.ManualResetEvent' to type 'System.Threading._ThreadPoolWaitOrTimerCallback'.`
The Application runs multiple times on the target machine (win7 x64).
The Application is a x86 application.
There have never been issues before I was forced to compile the Application to the .net 4.6+ target framework. But I need to go up to at least 4.6 due to other dependencies now.
I thought it could be a issue with garbage collection and set <gcConcurrent enabled="false"/>. But this did not help.
I tried to debug the miniDumps with WinDbg. But I was not successful to find a way to track the Issue down to a specific line of code or a method in my code. I don't think it is a .net issue, but I have no clue how to find the corresponding line in my code.
Edit on request:
Former .net target framework: 4.5.1
The application crashes randomly, could be after more than 24h
I'm not able to figure out in which part of my code the application crashes
The same application runs independent parallel on the same machine. Sometimes randomly one or two instances crash.
I search a way to locate UnhandledException in a native c++ desktop application. The error occurs in a .net assembly that is called by in process com interop. Problems are I do not know witch assembly causes the UnhandledException and I can not reproduce on my developer machine, so I can not simply use the debugger.
I try with AppDomain.CurrentDomain.UnhandledException but I think each com call get it's own AppDomain. Whatever it does not work, app is still crashing and event is not triggered.
Also I try to use stackify prefix, but may app is not an webservice and not an windows service, so this does not work.
Event logs are written but do not point to the error.
Any idea how I could identify the assembly causing the problem?
-- Edit --
Not all assemblies used via com interop are my own, so it is not that easy to add code to all of them.
Erros in event log is:
Source: .Net Framework
ID: 1026
Message: The process was terminated on a unhandeled exception.
Errorcode c0000005
I have a small C# console application that copy to a server, where it runs just fine.
However, if I call the .exe using a shortcut from another machine, it crashes. Any dependencies are also present on the calling machine.
In the eventview on the calling machine, all I'm getting is:
Faulting module name:
KERNELBASE.dll, version: 6.2.14393.2189, time stamp: 0x5abdad60
Exception code: 0xe0434f4d
Any ideas to help?
The returned exception is an error with permissions - see the following MSDN forum post;
https://social.msdn.microsoft.com...
It surmises that by default .NET security does not allow you to run .NET programs directly from a network share. The error itself is from a COM object - "Exception from COM object".
I have a similar problem to this question C# windows appication Event: CLR20r3 on application start
The error is like this:
Application: MantenedorPlanesMain.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Battery:
in CefSharp.Example.CefExample.Init ()
in CefSharp.WinForms.Example.Program.Main ()
But only on some machines, for example, on my computer I can use the program without any problem and in a computer of my office too.
I tried to find the source of the problem here in stackoverflow and realized that the error was caused by a cs file not found, but is within the project.
When I go to see CefSharp.WinForms.Example.Program.cs and comment the line of CefSharp.Example.CefExample.Init() throws me the same error in another file.
I tried everything, even the CopyLocal = true and x86, but still not working. I think there may be a problem with the system language, which is the only common factor of the machines that worked, Spanish language system.
any ideas?
In this context FileNotFoundException usually means you need to install VC++ or that you compiled in Debug mode (You need to build in Release mode when running on a machine without VS installed)
https://github.com/cefsharp/CefSharp/blob/master/NuGet/Readme.txt#L18
Also See the Note within https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#6-how-do-i-include-the-visual-studio-c-2012-redistributables-on-the-target-app