I have a file, Mineral.cs, and whenever I try to replace the method InitializeMinerals() with a static constructor Visual Studio crashes. This reoccurs over and over each time after restarting. What?!
Error Reports from Event Log:
Event 1000, Application Error:
Faulting application name: devenv.exe, version: 10.0.30319.1, time stamp: 0x4ba1fab3
Faulting module name: cslangsvc.dll, version: 10.0.30319.1, time stamp: 0x4ba20c61
Exception code: 0xc0000005
Fault offset: 0x0024b651
Faulting process id: 0x1904
Faulting application start time: 0x01d012904f2726d1
Faulting application path: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe
Faulting module path: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\VCSPackages\cslangsvc.dll
Report Id: f146768b-7f33-11e4-80e9-083e8e5a419a
Event 1001, Windows Error Reporting:
Fault bucket , type 0
Event Name: APPCRASH
Response: Not available
Cab Id: 0
Problem signature:
P1: devenv.exe
P2: 10.0.30319.1
P3: 4ba1fab3
P4: cslangsvc.dll
P5: 10.0.30319.1
P6: 4ba20c61
P7: c0000005
P8: 0024b651
P9:
P10:
Attached files:
C:\Users\CLASSIFIED\AppData\Local\debuggee.mdmp
These files may be available here:
C:\Users\CLASSIFIED\AppData\Local\Microsoft\Windows\WER\ReportArchive\AppCrash_devenv.exe_df1fb0912a591be97726252b29e971ef71bcbe74_0737cf24
Analysis symbol:
Rechecking for solution: 0
Report Id: f146768b-7f33-11e4-80e9-083e8e5a419a
Report Status: 0
Code in file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace XXXXXXXX.XXXXXXXXXX.Content.Items
{
public class Mineral
{
public static void InitalizeMinerals()
{
}
public Mineral(bool gem, string name, string[] subtypes = default(string[]))
{
this.IsGem = gem;
this.Subtypes = subtypes;
this.Name = name;
}
public bool IsGem
{
get;
private set;
}
public string[] Subtypes
{
get;
private set;
}
public string Name
{
get;
private set;
}
}
}
First, in C#, you can't have access modifiers on a static constructor.
Second, a little info about static constructors. They are used to initialize static data of the class, and are not called until just before the class is needed. So the first time you instantiate the Mineral class is when the static constructor is called. See this site for more details:
http://msdn.microsoft.com/en-us/library/k9x6w0hc.aspx
Third, if you are creating an instance of your Mineral class in a Windows Form object in either the XXX_Load method or the constructor, then the Mineral static constructor will be called. Static constructors can play merry hob with your designer (and cause it to crash with strange errors). If you don't have to instantiate the Mineral class on Form creation/loading, don't. You can test to see if this is the case by simply commenting out the code that creates/relies on the Mineral class in your form and then trying the designer again. If no exception, then the static constructor for the Mineral class was probably throwing an exception when the designer tried to load the class. This kind of error usually only affects the designer, and the program can run perfectly fine.
Related
I am experimenting with Visual Studio 2022 and EF Core 6. I created a solution with three projects, one with my razor pages one with my dbcontext and one with my entity. I was able to get the migration working with no issue, creating the database and single table which to me indicates I have everything working properly, but when I go to add a razor page and allow VS to wire up a "List" template for me, it spins for a minute and gives me an error: A type with the name Scaffolding.Entities.EncylopediaEntry does not exist.
Here is the class that apparently doesn't exist
using System.ComponentModel.DataAnnotations;
namespace Scaffolding.Entitites
{
public class EncylopediaEntry
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
}
And here is the DbContext with a hard coded connection string for now as I'm trying to figure out why scaffolding isn't working
using Microsoft.EntityFrameworkCore;
using Scaffolding.Entitites;
namespace ScaffoldingTest.Data
{
public class ScaffoldingContext : DbContext
{
public DbSet<EncylopediaEntry> encyclopediaEntries { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("{remove}");
}
}
}
I'd got same error. Visual Studio 2022 (preview too) with NET 6.0.
I installed NET 5.0 and tested with new project net 5 then works well.
But not with NET 6.0.
Why do I see this error when trying to open the control designer in visual studio 2019 and how do I fix it?
(Winforms)
The error switches sometimes when I try to open the designer:
I tried reinstalling Visual Studio but I am still getting this.
CustomContol1.cs
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DBControls
{
public partial class CustomControl1 : Control
{
public CustomControl1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}
}
CustomContol1.Designer.cs
using System.Windows.Forms;
namespace DBControls
{
public partial class CustomControl1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
you do not have a usercontrol, but you have inherited from Control.
This means there is nothing to design, and therefor the designer crashes
If you wish to build a usercontrol that you can edit in the designer, than you need to inherit from UserControl instead.
I am not sure if you can just edit this file and get it working, normally you have to use create new project and then choose customcontrol to do this.
here is an example on how to choose a project for this
this will create a dll that you can use in other project, in those projects you will have to click right mouse in the Toolbox and then choose items.
In the next screen you need to browse to the dll you created here and select it.
From then on all controls in that dll will be available in that project to drag onto forms
I can't believe I'm having such a hard time with this, but can someone give me a quick example of a COM interface in C# that is to be called from VB6? I want to pass parameters from VB6 to C#, and return a string to VB6.
Here's what I've got so far (not working):
[ComVisible(true)]
public interface IMonitor
{
string IPAddress(Int64 UserId, Enums.ClientTypes clientType);
}
I also tried:
[ComVisible(true)]
public interface IMonitor
{
void IPAddress(Int64 UserId, Enums.ClientTypes clientType, [Out] string ipAddress);
}
Same error - Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic.
FWIW, the ClientTypes enum works great in other VB6 code, so I don't believe the enum to be an issue.
Ok so let's say I have the following class in C#:
class Foo
{
public void Bar() { Console.WriteLine("FooBar"); }
}
In Visual Studio, whenever I instantiate my class and implement my method intellisense looks like this:
All this is showing is the name, return type and input parameters of my method. When viewing any method inside any of the .Net base classes using intellisense, a description is provided.
How do I add a description for my own methods to intellisense, so anybody who uses a *.dll I have written in the future can understand what my methods do without having to refer to external documentation?
Thanks
Add xml documentation :
/// <summary>
/// Foos something
/// </summary>
public void Foo()
{
}
If you copy this into VS2010 it sobs and dies. Why?
A colleague sent this to me in a mail saying that this is why the dynamic keyword is dangerous and warning that it'd kill VS, I copied it into what I was working on and lo and behold, VS2010 crashed.(Destroying most of what I'd worked on that morning).
Warning , it'll kill VS without compiling or any other input, if it's there VS will crash.
namespace Crash
{
public class Foo
{
public static void Method(object o)
{
}
}
public class Bar
{
public Foo Foo { get; set; }
public static void Method(dynamic d)
{
Foo.Method(d); //This crashes VS instantly!
}
}
}
Someone has already logged a bug for this.
http://connect.microsoft.com/VisualStudio/feedback/details/704397/vs-crash-when-passing-dynamic-val-to-static-member-of-class-from-a-static-method-in-c
Conditions necessary to cause the crash:
The static method being called must be referenced via only the class name (i.e. without a namespace).
The method making the call must also be static, and the class it belongs to must have a non-static property with the same name as the class whose method is being called.
The dynamic value being passed to it can come from anywhere - it doesn't have to be an argument to the calling function as in the example.