Changing .NET framework causes System.AccessViolationException - c#

I have a big problem which makes me cry everytime when I try to resolve it.
I have installed VisualStudio2012 Express and made project in .net 4.5 framework it is simple project which use QUARTZ library and has only 2 lines:
var cron = new Quartz.CronExpression("0 * 8-22 * * ?");
DateTimeOffset? nextFire = cron.GetNextValidTimeAfter(DateTime.Now);
I successfully have compiled application and it works fine. But one day I had to change framework from .net4.5 to .net 4.0 and when i did it VisualStudio throws errors in line
DateTimeOffset? nextFire = cron.GetNextValidTimeAfter(DateTime.Now);
Exception is:
"An unhandled exception of type 'System.AccessViolationException' occurred in WindowsFormsApplication6.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I tried to change framework from net4.0 to .net4.5 because in .net4,5 application worked fine but it does not works! I can go back to .NET4.5 but application throws the same System.AccessViolationException.
Have Anyone know how to resolve this issue?

I was facing this same problem.Somehow my project configuration for build was set x86.
It was not giving me option to change it.I unloaded project and changed it in notepad.Build configuration was set as "AnyCPU" and things started working problem

Related

The type initializer for 'Sybase.Data.AseClient1.AseConnection' threw an exception

I created ASP.Net web application in Visual Studio 2019.
This application uses Sybase.AdoNet2.AseClient.dll to connect to Sybase database.
InnerException = "Could not load C:\Users\....\AppData\Local\Temp\Sybase.AdoNet2.AseClient.32bits.2.157.1410.0\sybcsi_openssl210.dll"
the project target framework is .Net Framework 4.5
How do fix this issue?
First, you need to install nuget package -> AdoNetCore.AseClient.
Then, please use using AdoNetCore.AseClient; in the top of code.
Finally, you can use the following code without any exception.
AseConnection connection = new AseConnection();
Besides, we need to note that we have to use .net core app because the limit of AdoNetCore.Aseclient.
Finally i use the old version 2.157.1000.0 to Fix this problem.

Unable to run Console Application from Visual Studio: System.AccessViolationException

Description
When launching any Console Application, the code stops running immediately on an AccessViolationException (Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt). More info included in the next section.
Technical Symptoms
The Call Stack only contains external code:
Exception:Thrown: "The message filter indicated that the application is busy. >(Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))" (System.Runtime.InteropServices.COMException)
A System.Runtime.InteropServices.COMException was thrown: "The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))"
Time: 12/10/2015 10:59:55 AM
Thread:vshost.NotifyLoad[15344]
I created a new Console Application, containing only Console.WriteLine("Hello world!");
Running the new Hello world app results in the same exception and an identical
call stack.
Background
I suspect this has nothing to do with the issue, as I will explain, but I feel it is important to answer the obvious question, "what were you doing when the issue happend?" The last change I made was adding an extension to my Selenium Driver to hotkey logout from an application:
public static void logout(this IWebDriver Driver)
{
Driver.FindElement(By.TagName("body")).Click();
new Actions(Driver)
.SendKeys(Keys.Control + Keys.Shift + "x")
.Perform();
}
I also made a change in my App.Config file for one of my projects, but reverting this had no impact either.
Removing this code (the Driver extension and/or the App.Config change) does not resolve this issue. Retrieving a previous check-in does not resolve the issue. I am the only person currently working on this solution.
Discoveries
As mentioned, this is happening for an empty Console Application. Windows Form Applications launch fine. Unit Test Projects launch fine as well.
Research
I've spent hours looking into this. It seems like every similar issue I have looked into is pertinent to debugging only or a .NET version. For me, the issue occurs with a Release as well. Additionally, I have been using .NET 4.5 without any issues or changes on that front. I can't find any articles that seem worth posting, but I might be overlooking something.
Visual Studio Info
Microsoft Visual Studio Ultimate 2013
Version 12.0.30501.00 Update 2
.NET Version 4.6.00081 (just noticed it says 4.5 in my project properties, though)
Running as Administrator
Feedback
When Running from devenv.exe /SafeMode, Visual Studio loaded with:
An exception was encountered while constructing the content of this frame. This information is also logged in "C:\Users\UserName\AppData\Roaming\Microsoft\VisualStudio\12.0\ActivityLog.xml".
Exception details:
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.VisualStudio.Shell.Interop.IVsShell5.LoadPackageWithContext(Guid& packageGuid, Int32 reason, Guid& context)
at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.GetPackage()
at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.ConstructContent()
Additionally, when trying to run, I get an error message of "Error while trying to run project: Invalid Pointer" (again, VS in devenv.exe /SafeMode - see how to run visual studio without plugin and all third party feature if unfamiliar)
Please let me know if I can provide any additional information.
It may be because when you name the project you can't put spaces, I put them and it gave me a AccessViolationException aswell, try using capitals to separate your words, but only use letters and no spaces to be sure.
I also faced this issue with Visual Studio 2010. More interestingly I had several projects in my solution (Console application, WPF application, Windows Forms application) but it was failing only when, I was setting the project which was of type "Console Application" as start up project. Following change finally helped me nail down the issue: Go to project properties of the console application project -> Go to "Debug" tab -> Go to "Enable Debuggers" section in right pane -> Check the "Enable unmanaged code debugging" check box as shown in the snapshot below. Root cause of why it happened is still not known to me. Only thing which I observed as fishy was that there were lot of windows updates which had got installed on my machine the previous night which mostly constituted of office updates and OS updates (More than a dozen KB articles).

TypeLoadException from log4net LogManager.GetLogger

I'm attempting to use log4net to provide logging in a Windows CE/Windows Embedded project. However, when debugging the project I get the following exception
System.TypeLoadException occurred
Message="TypeLoadException"
StackTrace:
at log4net.LogManager.GetLogger(Assembly repositoryAssembly, String name)
at log4net.LogManager.GetLogger(Type type)
at Sis.SiLogCE.Broker.StartBroker..cctor()
at Sis.SiLogCE.Broker.EntryPoint.Program.Main()
from the following line:
private static readonly ILog log = LogManager.GetLogger(typeof(StartBroker));
At first, I thought I might have been using the wrong dll/an old dll so I downloaded the most recent version - I am using the log4net.dll from 1.2.12-bin-newkey and found in .net-cp 3.5.
I've looked though other examples and though the documentation and I can see no reason why I'm getting a type load exception here. I'm now pretty much out of ideas as to what couple be causing the exception.
Background information:
Application is to be deployed on Windows CE 6 and Windows Embedded/Windows Mobile 6 and 6/5 devices.
.net 3.5
.netcf
The following block shows loading the config for log4net from an XML file named "log4net.config".
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().
GetModules()[0].FullyQualifiedName) + "log4net.config";
if (File.Exists(path))
{
XmlConfigurator.ConfigureAndWatch(new FileInfo(path));
}
EDITS:
Up until now, I've only tested on Wince 6.0 so I've just had a shot with Windows Mobile 6.5 - it's no different, the same exception is presented.
Are you using the binary release, or have you built from source ? I ask as this page mentions that Compact Framework 1.0 & 2.0 are not supported by the binary release, but are supported if built from the source release.

Issue with Linq, NpqSql and Entity Framework on one machine only

We have an environment that has been successfully running a postgresql web application with
Entity Framework running on .net 4.0.
Somehow, on my machine only, a single Linq query fails where on others it is successful. The following is the linq query, context of which doesn't particularly matter. Point is, it works on other machines and not mine. Additionally, my machine can successfully do inserts and the like but not this one specific execution.
((SEntities)Context).c_app.MergeOption = MergeOption.AppendOnly;
app = (((from rec in ((SEntities) Context).c_application
where rec.app_id == CStatus.app_id
select rec) as ObjectQuery<c_application>)
.Include("c_status")
.Include("c_tasks")
.Include("c_product")
.Include("c_acct")
).SingleOrDefault();
On co-workers machines, a fresh checkout running in the same server configuration yields a succsful result.
However, on mine, the following is the exception I get:
System.Exception {System.Data.EntityCommandExecutionException}
InnerException:
{"ERROR: 42601: syntax error at or near \"LEFT\""} System.Exception {Npgsql.NpgsqlException}
If I look at the errorSQL entry in the debug window that comes up, a huge SQL is created with "select .... limit 2 left join..." which is invalid and where the error is occurring.
The question is, why is this only happening on my machine, and my compiled code deployed to the others and/or the same code executed on co-workers working? We have recently upgraded to a 64 bit app pool but the DLLs are deployed with it and from the output, are the correct ones.
Obviously I'm missing something on my machine but it's not in our source so its either an iis config or something in the gac that has caused problems.
Edit:
Despite checking, I had installed 4.5 when I did a developer preview install of Visual Studio. Since 4.5 is an in-place upgrade from 4.0, I was missing everything where it said "target 4.0" despite being 4.5. Apparently Microsoft fixed a bunch of bugs in 4.5 for Entity Framework (or made more) and this was one of them. Other people have had similar issues so not sure if it was a bug in 4.0 or a bug introduced in 4.5.
The following fixed the above for anyone who somehow may have
string sql = "SELECT VALUE a FROM c_application AS a WHERE a.app_id = #appId";
ObjectParameter[] queryParams = { new ObjectParameter("appId", CStatus.app_id) };
ObjectQuery<c_application> query = Context.CreateQuery<c_application>(sql, queryParams).Include("c_status").Include("c_tasks").Include("c_product").Include("c_acct");
CApplicationDao cApplicationDao = new CApplicationDao();
SetupDao<c_application>(cApplicationDao);
query.MergeOption = MergeOption.AppendOnly;
app = credApplicationDao.FindSingle(query);

How can I solve a TypeInitialization exception in my app when deployed?

My app runs fine on my machine (of course/famous last words). However, when deploying it to another machine on the network, it won't even start up. I ran my EventLog utility on that machine and it told me this:
Type:Error
Source: .NET Runtime
Time Generated: 06/12/2012 15:35:12
Message: Application: duckbilledPlatypus.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeInitialization
Exception
Stack:
at duckbilledPlatypus.PlatypusMainForm..ctor()
at duckbilledPlatypus.Program.Main()
So it's something in my main form's constructor that's the problem, apparently...which, I admit, is a little "busy":
InitializeComponent();
foreach (string arg in Environment.GetCommandLineArgs())
{
if (arg == "-DEBUG")
{
InDebugMode = true;
break;
}
}
SuspendLayout();
tsch = new ToolStripControlHost(dateTimePickerScheduleDate);
toolStripPlatypusMain.Items.Add(tsch);
CreateTableLayoutPanelAndChildren();
LimitPlatypusIDTextBoxesToOneChar();
ShareEventsAmongDynamicTextBoxes();
SetAllPlatypusDataControlsReadOnly();
ResumeLayout();
Does any of this look problematic? (it's all pretty standard stuff, except for the ToolStripControlHost).
Now as to the framework version: does the Event Log report the framework version used to create my app, or the framework version installed on the machine trying to run the app? If the former, and the latter does not have that framework installed, that's a problem, right?
So if that's potentially the problem, how do I determine which version of the .NET runtime is installed on that machine?
UPDATE
I don't know why this is, but I was able to see an err msg after running the app on the remote/deployment only when I right-click and select Run As (and ran as myself, as I don't have any "more special" privileges on that machine). When I did so, I got "Unable to find a version of the runtime to run this application."
If I simply 2-click the app, it dies without a whimper (no err msg).
View the
view the %WINDIR%\Microsoft.NET\Framework directory
to determine which versions of .NET are installed.
http://msdn.microsoft.com/en-us/library/y549e41e.aspx
Try running the Fusion Log Viewer on the problematic machine. It will provide details about binding failures.
http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.100).aspx
Make sure you run it as administrator. It silently fails if you do not.
UPDATE
Based on your error "Unable to find a version of the runtime to run this application.", I would suggest you don't have the same version of .NET installed on the box that your application targets. Did you verify the installed versions using the steps above?
Also see
.Net framework - "unable to find a version of the runtime to run this application"

Categories