I have developed an application using .net 3.5 and have deployed it as an .exe on a number of machines with the same environment.
However, on one particular machine I get the following error. Stack Trace:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
System.InvalidOperationException: Unable to generate a temporary class (result=1).
error CS2001: Source file 'C:\WINDOWS\TEMP\wz58eig4.0.cs' could not be found
error CS2008: No inputs specified
at System.Xml.Serialization.Compiler.Compile(Assembly parent, String ns, XmlSerializerCompilerParameters xmlParameters, Evidence evidence)
at System.Xml.Serialization.TempAssembly.GenerateAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, Evidence evidence, XmlSerializerCompilerParameters parameters, Assembly assembly, Hashtable assemblies)
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location, Evidence evidence)
at System.Xml.Serialization.XmlSerializer.GetSerializersFromCache(XmlMapping[] mappings, Type type)
at System.Xml.Serialization.XmlSerializer.FromMappings(XmlMapping[] mappings, Type type)
at System.Web.Services.Protocols.SoapClientType..ctor(Type type)
at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor()
at SSOClient..ctor()
at sc.tradesvc.SSOManager..ctor()
at sc.tradesvc.SSOManager.get_Inst()
at sc.cashflowgenerator.Controls.LoginForm.btnLogin_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.PerformClick()
at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.TextBoxBase.ProcessDialogKey(Keys keyData)
at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
Loaded Assemblies:
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
CashflowGenerator
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/DATA/DEVEL/Output/CashflowGenerator.exe
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
System.Core
Assembly Version: 3.5.0.0
Win32 Version: 3.5.21022.8 built by: RTM
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll
System.Web.Services
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Web.Services/2.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Could someone help me with this?
As I am new to .net could someone also tell me when why a temporary class needs to be created in the first place?
I just spent a lot of time searching for the answer to this so I thought I'd add it here to save some headache for others. If you use the xsd.exe tool to generate your cs it may have added double arrays [][] where an array should be []. Replace all [][] with [] in your generated cs file and retry.
XML Serialisation works by generating code to perform the serialisation. This is done in a temporary assembly created for that purpose the first time it is needed.
However this relies on being able to write the assembly to disk.1
Your options are either to (1) given the user account which is running the process write permission (for an ASP.NET application this is likely to be a bad idea). (2) Use the SDK tool (sgen.exe) to pre-generate (at development/compile time) the serialisation assembly, and then use (and deplot) that assembly.
1Open question: the APIs exist to create assemblies dynamically in memory: why not do that?
You only have to give the List Folder Contents and Read permissions on %windir%\Temp.
I found this post when trying to fix my problem, and didn't have to give my user account write access.
From Microsoft
You Need to give the permission to the temp folder which is in windows folder. And Your Problem is Solved...........
You need to add *IIS_IUSR* user with read write permission to C:\Windows\Temp folder.
NOTE: Everyone user will not work with full control.
Surfacing #grzenio's comment a bit further for recent users:
If you go to Project Properties -> Build -> Generate serialization assembly -> On, it forces the generation of the XML serializers assembly at compile time, eliminating the need to do so at runtime.
In turn, this means you don't need to change filesystem permissions (useful if you're, for example, hosting on Windows Azure Web Sites, where that isn't an option).
It may be also just some simple error in the serialized class (typically a result of some copy/paste). For example the following class will cause this error:
public class Foo
{
private string[] contexts;
/// <remarks/>
[System.Xml.Serialization.XmlArrayItemAttribute("Context",
typeof(Property), IsNullable = false)]
public string[] Contexts
{
get { return this.contexts; }
set { this.contexts = value; }
}
}
Notice that typeof(Property) parameter in XmlArrayItem attribute is not compatible (most likely) with string causing similar exception:
System.InvalidOperationException:
Unable to generate a temporary class (result=1).
If typeof(Property) is replaced with typeof(string) serialization will work again.
the APIs exist to create assemblies dynamically in memory: why not do that?
Just a wild guess: I assume this possibility did not exist yet in .NET 1.0, or at least when the XmlSerializer was created and MS doesn't like changing existing behavior...
Give Read/Write Privileges to 'C:\WINDOWS\TEMP' folder. It will work.
It may be bacause you are switching application pooling identity in IIS
to be password instead of predefined
so you have one off the following
return to predefined
give prmission full control to user IWAM_WBSRV-01 on the windows temp folder
In case this helps anyone, my problem was coming from an inherited class used in the serialization. The problem went away when I made a full copy/paste of my class I was serializing and quit using ineritance. Unfortunately, the advantages of inheritance went away, but that is better than having this problem. (Hey, at least I'm pretty sure that's what solved it. Happened to do a reboot in there somehwere too.)
Windows 10 has Virus and threat protection - if you have Ransomware protection (controlled folder access) it will block sgen.exe by default. Add sgen.exe it to exception list.
sgen.exe is located here: C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools
Folder name may vary depending on your Framework version
Related
I am making speech to text app in C# window form it was working fine and running in vs but
when I made a exe file and then try to run it's show error
It seemed to work fine, and created build However, when I try to run the executable, I get the following error:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.AggregateException: One or more errors occurred. ---> System.DllNotFoundException: Unable to load DLL 'Microsoft.CognitiveServices.Speech.core.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Microsoft.CognitiveServices.Speech.Internal.SpeechConfig.speech_config_from_subscription(IntPtr& config, String subscriptionKey, String region)
at Microsoft.CognitiveServices.Speech.SpeechConfig.FromSubscription(String subscriptionKey, String region)
at WindowsFormsApp5.Form1.<RecognitionWithMicrophoneAsync>d__0.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at WindowsFormsApp5.Form1.button1_Click(Object sender, EventArgs e)
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.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
---> (Inner Exception #0) System.DllNotFoundException: Unable to load DLL 'Microsoft.CognitiveServices.Speech.core.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at Microsoft.CognitiveServices.Speech.Internal.SpeechConfig.speech_config_from_subscription(IntPtr& config, String subscriptionKey, String region)
at Microsoft.CognitiveServices.Speech.SpeechConfig.FromSubscription(String subscriptionKey, String region)
at WindowsFormsApp5.Form1.<RecognitionWithMicrophoneAsync>d__0.MoveNext()<---
************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4515.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
WindowsFormsApp5
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/sars/AppData/Local/Apps/2.0/ZJ219HRQ.5KL/ET7TTANM.RTB/wind..tion_0f35f8da978c8171_0001.0000_3df998e5cb956487/WindowsFormsApp5.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4515.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4488.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4390.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4190.0 built by: NET48REL1LAST_B
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4515.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4084.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Microsoft.CognitiveServices.Speech.csharp
Assembly Version: 1.23.0.28
Win32 Version: 1.23.0.28
CodeBase: file:///C:/Users/sars/AppData/Local/Apps/2.0/ZJ219HRQ.5KL/ET7TTANM.RTB/wind..tion_0f35f8da978c8171_0001.0000_3df998e5cb956487/Microsoft.CognitiveServices.Speech.csharp.DLL
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
it may be a versioning problem. check if you have the necessary versions of Microsoft Visual C++ Redistributable for Visual Studio installed.
Also, loading packages.config sometimes behaves incorrectly in newer versions of Visual Studio. Try following the steps from: https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference
In Solution Explorer, right-click on packages.config and select "Migrate packages.config to PackageReference...."
In the opening dialog, there should be Microsoft.CognitiveServices.Speech.Core in Top-level dependencies by default and no package compatibility issues.
Select OK to begin the migration.
After the migration is completed, rebuild the solution which should then run without problems.
Hope that helps
This error is common if you have tried to distribute just the .exe file from the compiled binaries. If this is the case, you should ensure that all the dlls and pretty much everything in the bin folder from you compiler output is distributed, this is referred to as an XCOPY deployment.
If you are using click-once deployment, then in the Application Files section of the publish options, make sure that all of the referenced files are included:
For my company I am tasked with finding a way to debug external processes and 'cs scripts'.
The thing i'm trying to achieve is letting project engineers (who do not have visual studio) debug the scripts they write.
We have quite a neat system where a project engineer can write a simple script for adding a bit more functionality to our main program (turning on lights on special input) (it's used a lot to inteface between custom I/O of customers and our software.)
So I thought a good point to start is checking out the csscript plugin for notepad++, For building a simple script (if it has a static void main) it is more than great, it is awesome. However I wanted to try the "Debug external process" feature and the moment i click on it i get this error:
************** Tekst van uitzondering **************
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at CSScriptNpp.DebugExternal.<GetProcessList>d__11.MoveNext()
at CSScriptNpp.DebugExternal.Repopulete(Boolean refetch)
at CSScriptNpp.DebugExternal.<Reload>b__8_0()
************** Loaded assembly's **************
mscorlib
Assembly-version: 4.0.0.0
Win32-version: 4.6.1076.0 built by: NETFXREL3STAGE
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
CSScriptNpp
Assembly-version: 1.0.46.0
Win32-version: 1.0.46.0
CodeBase: file:///C:/Program%20Files%20(x86)/Notepad++/plugins/CSScriptNpp.dll
----------------------------------------
System.Windows.Forms
Assembly-version: 4.0.0.0
Win32-version: 4.6.1055.0 built by: NETFXREL2
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly-version: 4.0.0.0
Win32-version: 4.6.1075.0 built by: NETFXREL3STAGE
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly-version: 4.0.0.0
Win32-version: 4.6.1068.2 built by: NETFXREL3STAGE
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
CSScriptIntellisense
Assembly-version: 1.0.14.0
Win32-version: 1.0.14.0
CodeBase: file:///C:/Program%20Files%20(x86)/Notepad++/plugins/CSScriptNpp/CSScriptIntellisense.dll
----------------------------------------
And quite frankly i have no idea what to do because all i do is:
open notepad++ -> plugins -> csscript -> Debug external process.
any that has any experience with this? or knows a better way?
I solved the problem by uninstalling notepad++ and removing all the plugins and leftover files/folders in Program Files (x86)\Notepad++
after that i reinstalled npp and downloaded the plugin again, now it works.
I'm trying to generate a native image of my .NET 4.0 application using Ngen using a 64-bit Windows 7. When Platform is set to x64 (or Any CPU) - Ngen fails, complaining that 'NGen cannot proceed because Mscorlib.dll does not have a native image.'
When compiling as x86 and using the appropriate Ngen - it works fine. Also, when changing the .NET version to 2.0 - it works. (When trying to Ngen the x64 application with the x86 Ngen, it tells me I should use the 64-bit version.)
More information:
This is (part of) what I see in CMD: The ellipses (= ...) are present in the original.
1> Compiling assembly mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 (CLR v4.0.30319) ...
1>mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
.
2> Compiling assembly Accessibility, Version=4.0.0.0,
Culture=neutral, Public KeyToken=b03f5f7f11d50a3a (CLR v4.0.30319) ...
.
2>Ngen failed to generate native code for image Accessibility,
Version=4.0.0.0,Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
because of the following error: NGen cannot proceed because
Mscorlib.dll does not have a native image (Exception from HRESULT:
0x80131F06)
Searching inside C:\Windows\assembly I found 3 mscorlib.dll's. One in GAC_32, one in GAC_64 (both in subfolders beginning with 2.0.0.0) and one in a subfolder temp.
When searching inside C:\Windows\Microsoft.NET I found six of them: two under assembly (in GAC's 32 and 64) both in folders that begin with 'v4.0...', and four in Framework's: 2 in Framework, and two in Framework64 (in each - one in 'v2.0...' and one in 'v4.0...').
Does this mean that only .NET 2.0 mscorlib's are really run as native images (when needed)? And why doesn't Ngen succeed in saving native images of .NET 4.0?
Bottom line: How do I create a native image of a .NET 4.0 application that targets x64?
This is unhealthy. The ngen-ed image of mscorlib.dll should have been created when .NET was installed on your machine. It is located in c:\windows\assembly\NativeImages_v4.0.30319_64\mscorlib\ab0a8fc3d086a3aaf942f366a12a9185\mscorlib.ni.dll. I'm not sure how well the hashed part of the directory name repeats from one machine to another.
You cannot see this file with Windows Explorer, you must use the command prompt. Go check to see if it there, something went seriously wrong when .NET was installed if it is missing. The ".NET Runtime Optimization Service" is the one that gets that job done, make sure you didn't disable it.
A standard mistake is running ngen.exe from a command prompt that isn't elevated.
I have a C# application which was written on a 32bit windows XP machine with Visual Studio 2005. The application runs fine on Windows XP machines, however when I try to run it on a 64bit Windows 7 professional machine, I get the following dialog-box on start up:
Here is the full text from the details.
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at ICSNeoCSharp.IcsNeoDll.icsneoTxMessages(Int32 hObject, IcsSpyMessage& pMsg, Int32 lNetworkID, Int32 lNumMessages)
at ICSNeoCSharp.FormDTCApplication.transmitFlowControl(Int32 myArbID) in C:\Documents and Settings\Administrator\Desktop\Adam Stuff ThinkPad\DTC Checker FINAL\frmDTCApp.cs:line 1750
at ICSNeoCSharp.FormDTCApplication.flowControlTimer_Tick(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\Desktop\Adam Stuff ThinkPad\DTC Checker FINAL\frmDTCApp.cs:line 5166
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5472 (Win7SP1GDR.050727-5400)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
DTC Checker V1.0
Assembly Version: 1.0.4960.25549
Win32 Version: 1.0.4960.25549
CodeBase: file:///C:/DTC%20Checker%20V1.0%20R3/DTC%20Checker%20V1.0%20R3.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5468 (Win7SP1GDR.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5467 (Win7SP1GDR.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5467 (Win7SP1GDR.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Microsoft.Office.Interop.Excel
Assembly Version: 12.0.0.0
Win32 Version: 12.0.6600.1000
CodeBase: file:///C:/Windows/assembly/GAC/Microsoft.Office.Interop.Excel/12.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Excel.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Has anyone else encountered this error and succeeded in solving it?
While your main app might be built for AnyCPU are you sure all the assemblies are AnyCPU? Do you have any native assemblies or assemblies that contain native code? Are they built against x86?
file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
This tells me that the app is running as an x64 process but it would appear that there is some assembly that isn't AnyCPU or x64 which is likely the cause of the BadImageFormatException.
One thing you can try is to run the application from a 32-bit command prompt (c:\windows\SysWow64\cmd.exe) to force it to be a 32-bit process and see if that works. If that works then there is definitely some assembly that is not AnyCPU.
Project Properties -> Build -> Platform target -> x86 may solve this problem.
One of the most common mistake is we forgot to change the test program and wrapper program to the correct platform. See the below image
(in the top bar it is showing the platform is x64 but you need to make sure if it is really exists in the 2nd image ...)
Make sure you have right configuration on the Configuration Manager...if your config do not match with the actual config of your c++ dll it will give BadImageFormatException.
I learned from the mistake after searching a lot ... and finally got this
In my case I had the 0x8007000B error because the app was running in 32 bit, on my 64 windows 7. I solved it by going in windows/syswov64 folder changing the MSVCR110.dll version 64 bit with the MSVCR110.dll version 32 bit.
(Just don't forget to put back the 64 dll after. Each time you need to run your 32 bit app, just move the dll 32 on it).
You could find the dll versions here (Unzip it before pasting into the syswov64 folder).
From my experience the cause of that error is the .Net Framework Version
Check your .Net Framework version and update and also
check the .Net version of your application.
The fix for me was to change the Application Pool in IIS. Open the application pool properties and go to Advanced Settings... Then change "Enable 32-bit Applications" to True. The default is False for a new one. The code part was set to "Any CPU" although I have fixed issues in the past by setting the CPU to x86.
My issue was solved by compiling with 32 bit as Wix currently doesnt have 64. Your installer msi will in any case be 64 bit
http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/64bit-bootstrapper-using-wix-td7582851.html
I would like to add also my finding: I unchecked in a project properties in Build tab a "Prefer 32-bit" and got this error. After re-checking, it was gone. I have Any CPU set as a target.
I am aware that this is not a definite solution, just a symptom-solving, but it might be of help.
I had this error when my solution called a 32 bit dll. In addition to making the platform changes referred to in other replies above, in VS2017 Project {yourproject} Properties Services, I had to change "Use Windows authentication" to "Use Forms authentication"
I had to combine solutions from 2-3 different answers to resolve the same error. The reason is, the final setup had dlls from both x86 and x64 platforms(in separate folders for separate exes).
1) I set the platform target of my main app as 64 bit and left configuration settings as it is and built it:
2) I set the Target platform of my Deployment project as x64.
3) The dlls were getting mixed between the folders so i checked source path of all dlls in the File Types Editor one by one and replaced them according to their architectures.
4) Finally built the deployment project with following configuration settings:
The above mentioned combination is the only one that worked.
I have made one c# application For estate Agent Management.
In that application i have one mdi form which has all the menus in it.
In that menu when i selects agent master , one form comes with Add agent button.
When On Add Agent button is clicked Another Window is opened with agent details to fill.
My problem is>> when i closes this form>>
"Attempt to read or write protected memory.This often an indication that other memory is corrupt"
Error Comes.
When i clicks ok on the message box of this application whole application gets closed.
When i normally runs the application through visual studio this error doesnt comes.
But when i runs the exe of the code this error comes.
Is there any solution for this error?
Am i making mistake in releasing or debugging the project?
My stack trace:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.TextBox.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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Anamol Estate
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///E:/Anamol%20Estate/Anamol%20Estate/Anamol%20Estate/bin/x86/Release/Anamol%20Estate.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
CodeBase: file:///C:/Windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
.NET Framework has similar problem. Try this fix.
When you run a Microsoft .NET Framework 2.0 Remoting application, you may receive the following error message:
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Additionally, this problem may occur in .NET Framework 2.0 Remoting applications on a computer that is running certain types of driver software or antivirus programs.
First you can try a memtest as there could maybe be a specific sector of your memory which when allocated to is causing this error. The latest current version is 4.2 the downloads section is a quite a scroll down.
Or
This has happened to me once before it was due to a virus changing headers in my exe files. I had formatted my pc and reinstalled everything and it worked fine in my case. I suggest you try this option.