Why do I see this error when trying to open the control designer in visual studio and how do I fix it? - visual-studio

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

Related

What's an xUnit runsettings equivalent?

We have several environments that had their own run settings when we used MSTest. Since Microsoft is abandoning MSTest we are switching to xUnit. Whether it's through a runsettings or a command line property, I need a way to specify TestRunParameters in my xUnit test. Does xUnit have a native way to do that like MSTest or do I need to come up with my own solution?
While you can still use RunSettings to control some aspects of vstest.console while using xUnit the current version does not have a native way to pass in parameters. I believe v3 is going to have some kind of parameter passing.
For now you could use environment variables but if you are running multiple tests sets in parallel on the same system you would have conflicts.
I use a base class which reads in a TestSettings.json file with the settings for that test set. Using the following code I am able to pass in new types and have them read in by the base class json reader.
/// <inheritdoc />
/// <summary>
/// Common TestBase which uses CommonSettingsModel. Use TestBase<T> to override with custom settings Type.
/// </summary>
public abstract class TestBase : TestBase<CommonSettingsModel>
{
}
/// <inheritdoc />
/// <summary>
/// Common TestBase for loading settings.
/// </summary>
/// <typeparam name="T">Type to read TestSettings.json file</typeparam>
public abstract class TestBase<T> where T : ICommonSettings, new()
{
/// <inheritdoc />
/// <summary>
/// Constructor loads Settings T
/// </summary>
protected TestBase()
{
Settings = SettingsUtil.GetSettings<T>();
}
/// <summary>
/// Settings T loaded from TestSettings.json
/// </summary>
protected T Settings { get; }
}
You could also do the same type of thing with a Class or AssemblyFixture for the tests.
public class DatabaseFixture : IDisposable
{
public DatabaseFixture()
{
Db = new SqlConnection("MyConnectionString");
// ... initialize data in the test database ...
}
public void Dispose()
{
// ... clean up test data from the database ...
}
public SqlConnection Db { get; private set; }
}
public class MyDatabaseTests : IClassFixture<DatabaseFixture>
{
DatabaseFixture fixture;
public MyDatabaseTests(DatabaseFixture fixture)
{
this.fixture = fixture;
}
// ... write tests, using fixture.Db to get access to the SQL Server ...
}
https://xunit.net/docs/shared-context

Bootstrapper with Ninject using asp.net webapi

I am trying to use Bootstrapper to do initialization for my application, ioc, automapper, configuration etc.
I need some direction on how to setup the ninject correctly in asp.net webapi using bootstrapper. With the following configuration, my apicontroller is not able to resolve the IMyService dependency. Looks like it's using different ninject kernal.
My NinjectWebCommon
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
GlobalConfiguration.Configuration.DependencyResolver = new MyResolver(kernel);
RegisterServices(kernel);
return kernel;
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
}
}
bootstrapper ninject registration
public class DIRegistration : INinjectRegistration
{
public void Register(IKernel container)
{
container.Bind<IMyService>().To<MyService>().InTransientScope();
}
}
public class MyService: IMyService
{
public string GetString()
{
return "My String!!!!!";
}
}
public interface IMyService
{
string GetString();
}
What i did to solve the problem is moving bootstrapper.Initialize(CreateKernel); to the IStartupTask implementation i have created for NinjectWebBootstrap. Basically use the IKernal injected by the Bootstrapper framework and run my registration and at the end set asp.net webapi and then set DepdendencyResolver with the custom resolve that takes in the injected IKernal instance.
DIRegistration is never used. So that binding does not exist.
I was trying to update the values directly in database but values were not updated in my WCF which uses entity framework using Ninject in svc file - the same way as in https://github.com/ninject/ninject.extensions.wcf/tree/master/src/Examples/WcfTimeService and using bootstraping.
If found out that if I recycle the IIS app pool, the data gets refreshed and it works as expected. I guess it IIS and Ninject which is creating this caching issue. Do you have any idea about it?

How do I provide custom Intellisense descriptions in Visual Studio

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()
{
}

Create keyboard shortcut to regionate method

Can I in Visual Studio create keyboard shortcut to regionate method and auto-document it with GhostDoc?
From this:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
I want make this:
#region protected override void OnInit(EventArgs e)
/// <summary>
/// Raises the <see cref="E:Init"/> event.
/// </summary>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
#endregion
I am not sure about the GhostDoc auto documentation, but to regionate selected text you can use the "surround with" function in Visual Studio.
Select a portion of code and press Ctrl + K, S. This brings up the "surround with" context menu. Select "region" in the menu, type in your region name and you're all set.
This function can be used for a bunch of other stuff as well. If, for, while and try statements and so on.
Type three slashes to auto-generate the documentation

Automatically adding .Net code comments

Where can I find a Visual Studio plug-in that automatically generates documentation header for methods and properties?
Example the comment to a property could look like this:
/// <summary>
/// Gets or sets the value of message
/// </summary>
public static string Message
{
get
{
return message;
}
set
{
message = value;
}
}
Ghostdoc from http://www.roland-weigelt.de/ghostdoc/
GhostDoc is the usual suspect.
As another poster mentioned, Visual Studio also does this to an extent by entering 3 '///' (forward slashes) on the line preceding a property/method/class definition.
Visual Studio does this automatically. Just position the cursor directly above the method and enter three '/'s
for example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcWidgets.Models
{
/// <summary>
/// This is a summary comment
/// </summary>
public class Comment
{
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <param name="birthdate"></param>
/// <param name="website"></param>
/// <returns></returns>
public int SomeMethod(string name, DateTime birthdate, Uri website)
{
return 0;
}
}
}
You can then generate an XML comment file and then generate a Help file using SandCastle.
You may have to enable this feature in the Text Editor/C#/Advanced options dialog.

Resources