Access Violation Exception only appearing when running C# app without debugger attached - c#

I have an application that works fine in Visual Studios 2008, and I am trying to get it into VS 2010 in order to use .NET 4, and I have a really weird problem. When I run the code from either Release mode or Debug mode with the debugger attached (F5), I have no problems running the program. However, when I run the program from either Release or Debug without the debugger attached (Shift+F5), I get an Access Violation Exception when I attempt to run some code in a dll from GDCM. I've created the dlls by using CMake and Swig and following the instructions here adjusting the instructions where necessary to build for VS 2010 and .NET 4.
Does any one have any ideas why this is happening and how I can fix it?
Here's an example of a program where the error occurs. Again, if you create a project with the following as the program in VS 2010 it will run fine when the debugger is attached and fail if the debugger is not attached.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using gdcm;
namespace GDCMVS2010Test
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("This program prints the patient name of a dicom file with gdcm");
Console.WriteLine("Usage: [input.dcm]");
return;
}
gdcm.Reader reader = new gdcm.Reader();
reader.SetFileName(args[0]);
reader.Read();
gdcm.File file = reader.GetFile();
gdcm.StringFilter filter = new gdcm.StringFilter();
filter.SetFile(file);
string value = filter.ToString(new gdcm.Tag(0x0010, 0x0010));
Console.WriteLine("Patient Name: " + value);
}
}
}

You should really start using GDCM specific groups to communicate your issues, see:
http://sourceforge.net/apps/mediawiki/gdcm/index.php?title=General_questions#Where_are_the_GDCM_mailing_lists_.3F
100 of GDCM users are on this list and will be able to help you.
You should also provide a dataset (the DICOM file) to help with reproducing the bug.
Thanks

The client profile misses out chunks of the .Net framework that you are unlikely to need on a client machine. ASP .Net for example. See this link http://msdn.microsoft.com/en-us/library/cc656912.aspx

This was because the version of SWIG I was using wasn't working correctly. A new version of SWIG was recently released (version 2.0) which solves this problem. After I reran CMake on GDCM, and then rebuilt GDCM with VS 2010, and put the GDCM dlls back into my example code, everything worked fine.

Check your project properties. I have encountered this problem when I had my Target Framework set to .NET Framework 4.0 Client Profile, when it should have been the one w/out Client Profile. Or vice versa.

Related

VS Code will not display errors in my C# script for Unity (possible omnisharp problem)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Driver : MonoBehaviour
{
void Start()
{
}
void Update()
{
// transform.Rotate(0,0,0.1f);
transform.Translate(0,.01f,0);
}
}
above is my code. If I add anything incorrectly, no error appears. It appears to be a problem with omnisharp. I have tried reinstalling, fidgeting with the settings, and installing older versions of the C# extension. However, no matter what I change, errors do not appear as I code.
VS Code cannot automatically complete the code or check errors, and the plugin fails.
The following steps are helpful:
First make sure the plugins are installed.
List of plugins:
Debugger for Unity.
Unity Tools.
Unity Colde Snippets.
Make sure the development environment is complete.
An incomplete development environment can also cause this problem. It is also possible that the .net version created by the project does not match the .net version of the development environment.
Solution:
2.1. Use a text editor to open the file with the extension csproj in the root directory of the project.
2.2. Ctrl + F Search "TargetFrameworkVersion" keyword, you can see the information "v4.7.1". This means that your computer lacks the 4.7.1 version of .net Framework, and different computers default Versions may vary.
2.3. Microsoft official website to download the corresponding version. It should be noted that you need to download the develop pack (development package) version, not the normal version. Otherwise useless.
2.4. Restart vscode.
VS code editor settings.
3.1. Enter the vscode editor and press ctrl + shift + P at the same time.
3.2. Enter in the pop-up input box: OmniSharp: select project.
3.3. Manually select the project file.
Normally, vscode cannot complete the error check because the version of omnisharp is wrong, omnishap may conflict with other versions of your vs code during the upgrade process, so you need to keep omnisharp to the latest version.
Solution:
4.1. Go to the console. Then click on the ouput bar and change the output type to ominisharp log. Windows version shortcut key: ctrl + shift + u.
4.2. Search for ominisharp in the setting.json file of vs code and change its path parameter to latest.
{
"[csharp]": {
"editor.defaultFormatter": "bilal-arikan.csharp-auto-formatter"
},
"omnisharp.path": "latest"
}
4.3. Restart vs code.
Hope it helps you.

Using C#, .NET Core 3 and GTK# for cross-platform Programming (and alternatives)

I am about to start development of a software project that should run on Linux and Windows if possible. As I already have some experience with C# I am eager to use it for this project. I assumed that with .NET Core 3 and GTK# 3.22 this shouldn't be a problem since .NET Core App should be cross-platform out of the box. GTK# - from my understanding - should work everywhere GTK+ in the same version is also available.
Why c#? Well I just like the language and there is an ECS Framework for c# I'd like to use.
So far I have setup a test Console App project in Visual Studio targeting .NET Core 3 and added an GTK# specific NuGet package.
I wrote a simple Hello World program for testing of the environment.
using System;
using Gtk;
namespace GTKTest
{
class Program
{
static void Main(string[] args)
{
Application.Init();
Window win = new Window("Hello GTK");
Label lbl = new Label("This is a test GTK App written with C# for GNU/Linux and Windows");
win.DeleteEvent += Win_DeleteEvent;
win.Add(lbl);
win.ShowAll();
Application.Run();
win.Dispose();
Console.Write("Press any key...");
Console.ReadKey();
}
private static void Win_DeleteEvent(object o, DeleteEventArgs args)
{
Application.Quit();
args.RetVal = true;
}
}
}
When I run this code from Visual Studio 2019 I get
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'Gtk.Application' threw an exception.
Source=GtkSharp
StackTrace:
at Gtk.Application.Init()
at GTKTest.Program.Main(String[] args) in D:\Workspace\VSRepos\C#\GTKTest\Program.cs:line 10
Inner Exception 1:
DllNotFoundException: Gtk
While searching for a solution I installed mono and GTK# for Windows from this page. The mono part shouldn't be necessary if I stick to .NET Core I think.
What am I missing? What am I doing wrong? Is what I'm trying to achieve even possible like I am imaging it? I'm also interested in some alternatives how to program cross-platform GUI-Software with C#. I stumbled upon electron.js but I heard it has some big Memory overhead and I'm not really into javascript. AvaloniaUI sounded interesting but I thought that the above approach would be better.
Edit: After adding msys path like suggested here in step 3 I get following error preceding the exception from above. The error states that the procedure entry point couldn't be found in the dll.
I know this is an old question, yet Google likes it.
I have had the similar problem. There are lots of guides that are easy to google but hard to make them work. Here is the guide that helped me as of April 2022:
Step 1: Install MSYS2
Download the MSYS2 installer and follow the installation instructions.
Step 2: Install GTK+3 Open a MSYS2 shell, and run: pacman -S mingw-w64-x86_64-gtk3
Step 3: Modify PATH variable so that the library can be found
Open up Control Panel
Go to System and Security > System
Click on the Advanced system settings link
Click on Environment Variables... button
Under System variables find the Path variable and select it
Click the Edit button
Add either ;C:\msys64\mingw64\bin or ;C:\msys32\mingw32\bin to the end of the variable, depending on your system architecture
Click OK, and you are done
Restart your system for the changes to apply
To run GtkSharp Samples project you would also need:
pacman -S mingw-w64-x86_64-gtksourceview4
Otherwise it throws ...System.DllNotFoundException: GtkSource: libgtksourceview-4-0.dll...
Then you may either install GtkSharp from here or from nuget.

C# Console Application build but not launch application

I have a simple Console Application write with C-Sharp language (Visual Studio 2013):
using System;
using System.Collections.Generic;
using System.Text;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World");
Console.ReadKey();
}
}
}
When I press F5 or click Start button, my project was built, but not launch.
Sometime, Ouput windows says:
Error 12 Could not copy "obj\Debug\HelloWorld.exe" to "bin\Debug\HelloWorld.exe". Exceeded retry count of 10. Failed.
Error 13 Unable to copy file "obj\Debug\HelloWorld.exe" to "bin\Debug\HelloWorld.exe". The process cannot access the file 'bin\Debug\HelloWorld.exe' because it is being used by another process.
but when I write Windows Form Application, my project was built and launch normally ???
Why? and How to solve this problem ?
This is most likely due to windows keeping the process open. Your only option is to try and kill all processes of your app in task manager->processes.
The next thing to try is to simply change the build from debug to release, this should build another executable in the release folder as opposed to debug. By no means is this a silver bullet but, hopefully a sufficient workaround.
Before you try the release build, attempt to try and fix the problem. I've seen windows moan at just having my debug folder open and my exe selected because I suspect the thumbnail was being displayed thus being "used" in windows etc.
I found reason and solve for my problem.
I tried to restart Application Experience Service and the problem was solved.
Please restart yor Visual Studio and then try again. It will work and delete your bin/debug folder again.
I have faced with this issue.
That happeneds when an instance of software is running whether by visual studio or by your self
solution :
you should find your application name in the processes of task manager
your's is :
HelloWorld.exe
select that and click on the end task button
now you can start debugging and running you'r app.
at least worked for me.

Using Visual Studio Code and using defined symbols

EDIT: I have edited the whole question, since this is not only for Unity3D, but at all .sln projects.
I have a installation of Visual Studio Code(Not Visual Studio, but this:https://code.visualstudio.com/) on my Macbook at work. VSCode is otherwise working just fine with normal and Unity3D projects. I get Intellisense on all classes, including Unity3D specific ones, like GameObject. So I think my installation and startup sequence is correct.
Only problem I have, is that VSCode does not seem to recognize constants defined in the .csproj files. First I noticed this with some Unity3D plugins, but it is persistent on normal Visual Studio projects too.
My sample project is a dummy application downloaded from internet, but it is fully working on MonoDevelop. This is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DummyConsoleApplication
{
class Program
{
static void Main(string[] args)
{
tester();
}
#if DEBUG
static void tester(){
}
#endif
}
}
The function call in Main causes a not found exception on the editor, but it compiles fine, since the .csproj file has this line:
<DefineConstants>DEBUG;TRACE</DefineConstants>
Any verification on if this is normal behaviour for VSCode would be greately appreciated. Also, if anyone is aware of any solution, even hacky ones, to get past this bug and force Intellisense to autocomplete would help out too.
The error I get is:
The name 'tester' does not exist in the current context [DummyConsoleApplication]
My hardware is a Macbook with Yosemite and my compiler is dnx-mono.1.0.0-beta4.
This is a known limitation with OmniSharp, the C# engine that Visual Studio Code is built around. There is an open enhancement request for adding <DefineConstants> support, but it is tied to a larger issue with regards to MSBuild Support.
Currently, this isn't a supported configuration under Visual Studio Code. You can try to define your constants through the launch.json instead, but support is minimal at best.
It should work...
As a sanity check, have you:
"Sync MonoDevelop Project" recently?
Make sure Visual Studio Code has the -csharp solution (.sln) selected? (Click the flame in the status bar to change)

f# console app doesn't work. c# console app does

I am attempting to deploy a simple f# console app to a coworkers computer but it keeps failing. After double clicking on the app icon, the console window appears but then the Microsoft error reporting window shows up asking if I would like to send the error report, I decline then some text flashes in the console window. It looks like an error message, but the window closes too fast to tell. The weird thing is, if I create a similar C# app, it works. I am targeting .net 4 client framework in release mode.
Here is the code
f# code (doesn't work):
open System
printfn "print test"
Console.ReadLine() |> ignore
c# code (does work):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestCApplication
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Testing...");
Console.ReadLine();
}
}
}
The F# analog of your C# snippet would be not your F# code, but the following:
System.Console.WriteLine "print test"
System.Console.ReadLine() |> ignore
While the app off 2-liner above will run, similarly to one off your C# snippet, just on raw .NET, use of printfn function in your F# code requires certain F#-specific core components being deployed on the target computer, which is likely not the case. The latter explains the observed behavior.
Look at the references of your F# project and you will see one to FSharp.Core which is normally located here:
C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v4.0\FSharp.Core.dll
On Windows 7 (64 bit) PC
Also look at the F# site to get the runtime download.
http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/release.aspx
EDIT: here is the direct link to the runtime download (thanks ildjarn):
http://www.microsoft.com/en-us/download/details.aspx?id=13450

Categories

Resources