SQLCommand Error on Visual Studio Designer (WinForms) - winforms

On a C# project (.NET Framework 4.8) when I try to create a control SqlCommand using the designer I get the following error
Failed to create component 'SqlCommand'. The error message follows: 'System.invalidCastException: Unable to cast object of type 'Microsoft.Data.SqlClient.SqlCommand' to type 'System.Data.SqlClient.SqlCommand'.
The same problem appears with Microsoft.Data.SqlClient V3 and V2.1.3 and older.
All other controls like SQLDataAdapter are ok.
Thanks in advance for any suggestions.enter image description here

Add Dependency "System.data.Common" in your project..

Related

DataGrid2D - 'Attachable Property' warning in VS 2019

I'm using the DataGrid2D component (installed via NuGet) to allow me to bind a 2D array to a datagrid in a .Net Core 3.1 WPF project using Prism.
https://github.com/GuOrg/Gu.Wpf.DataGrid2D/blob/master/README.md
Everything works it's just that the designer breaks and VS gives me the following warning for the code snippet shown below:
The Attachable Property 'Array2D' was not found in type 'ItemSource'
Here's the alias I included in the top of the xaml page:
Any ideas how to resolve this?
Sadly I think this may be just one of countless bugs in the WPF designer.
Does it work when you run it?
You can try a sad loop of closing vs, git clean, rebuild etc. and maybe it goes away.

XamlParse Exception when using visual component package

So I am making a WPF application and I need it to draw some charts. I've installed DynamicDataDisplay NuGet package but I get an exception when I try to add it to xaml.
Here are some picture to help you understand:
http://imgur.com/a/npLrO

Silverlight designer error

Whenever I open my Visual Studio 2010 Silverlight designer for xaml I am getting this error.
System.NullReferenceException Object reference not set to an instance of an object. at Microsoft.Expression.Platform.Silverlight.SilverlightDomainManager.CreateDomainCore() at Microsoft.Expression.Platform.Silverlight.SilverlightDomainManager.CreateDomainInitial() at Microsoft.Expression.Platform.Silverlight.SilverlightPlatformCreator.Initialize() at MS.Internal.Platform.SilverlightPlatformImpl.Initialize() at MS.Internal.Package.VSIsolationProviderService.RemoteReferenceProxy.EnsurePlatformInitialized() at MS.Internal.Package.VSIsolationProviderService.RemoteReferenceProxy.EnsurePlatformInitialized() at MS.Internal.Package.VSIsolationProviderService.CreateIsolationProvider(String originalIdentifier, Boolean isGlobal, String identity, FrameworkName frameworkName, AssemblyName appAssemblyName, IVsHierarchy hierarchy) at MS.Internal.Package.VSIsolationProviderService.CreateIsolationProviderWorker(String identifier, IServiceProvider provider) at MS.Internal.Package.VSIsolationProviderService.CreateIsolationProvider(String identifier, IServiceProvider provider) at MS.Internal.Providers.VSDesignerContext.CreateIsolationProvider(IServiceProvider provider, IVsHierarchy hierarchy) at MS.Internal.Providers.VSDesignerContext.<>c_DisplayClass1.b_0(IsolationProviderProxy i) at MS.Internal.Providers.IsolationProviderProxy.get_RealProvider() at MS.Internal.Providers.IsolationProviderProxy.add_UnhandledException(UnhandledExceptionEventHandler value) at MS.Internal.Designer.DesignerPane.LoadDesignerView()
Note:- I saw lot of references in online & in stackoverflow. Nothings works for me.
In this forum
http://forums.silverlight.net/t/168508.aspx kakone says "There were some old versions of Silverlight assemblies into the GAC.I used gacutil to remove all Version=2.0.5.0 silverlight assemblies. "
So maybe old assemblies cause conflicts.
See also
http://connect.microsoft.com/VisualStudio/feedback/details/543205/silverlight-rc-4-designer-dontwork
i dont know if you got the answer or not, but i had a similar issue a while back and here is what i did
Goto add/remove programs.
unistall both silverlight components. i.e. Silverlight and its SDK
Download this file and install it.
Restart Visual Studio, and now it should work fine

WPF VS2010 Upgrade - Now WPF designer throws exception when projects targets .NET framework 3.5

I recently upgraded a number of projects from VS2008 to VS2010. Now I'm having an issue at design time w/ the WPF designer in Visual Studio. It throws an exception for every XAML page I open in design mode. Exceptions also throw for new brand new XAML pages.
Projects currently target .NET 3.5. If I switch to target .NET 4.0, designer opens correctly.
Do note that projects build and run successfully.
The exception Details displayed in the WPF designer vary but scrolling to the bottom of the Details of all the exceptions do show something similar to:
The component 'MS.Internal.Interaction.AdornerFontResourceDictionary' does not have a resource identified by the URI '/Microsoft.Windows.Design.Interaction;component/ms/internal/interaction/adornerfontresourcedictionary.xaml'.
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at MS.Internal.Interaction.AdornerFontResourceDictionary.InitializeComponent()
at MS.Internal.Interaction.AdornerFontResourceDictionary..ctor()
at Microsoft.Windows.Design.Interaction.AdornerFonts.<.cctor>b__0()
at Microsoft.Windows.Design.Interaction.AdornerResources.EnsureResources(Boolean forceUpdate)
at Microsoft.Windows.Design.Interaction.AdornerResources.get_ThemeResources()
at MS.Internal.Themes.GenericTheme..ctor()
I'm guessing switching the framework targets is is causing the project to point to some older DLL. Any thoughts?
Following the upgrade, look through all the projects in the solution looking for references to any DLL named "Microsoft.Windows.Design*". Removing these references and recompiling will fix the issue.

What is the run-context for a form opened in the designer for a winforms application

I have a form that will not open in the designer. I used the technique that I mention in an answer to THIS questions...
Visual Studio WinForms designer does not instantiate object
...to determine why the form will not open in the designer.
The bottom line is that the form's load event tries to load some custom business objects which gets data from a database. The line that is failing is ...
Dim connStr As String = ConfigurationManager.ConnectionStrings(connectionStringName).ConnectionString
...this returns a null reference exception. It cannot find my named connectionstring in the calling context of opening the form in the designer while not in design mode.
Why is this? The connectionstring is in the app.config of the project that the form is in. All I can think of is that the Designer is opening in it's own context and does not use the app.config of the winforms project. In fact, in the break context...the configuration manager IS holding two connectionstrings...neither of which is in my projects app.config. They are as follows...
?configurationmanager.ConnectionStrings(0).ConnectionString
"data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
and
?configurationmanager.ConnectionStrings(1).ConnectionString
"data source="|DataDirectory|\aspnetdb.vdb3""
...I mention those as possible clues. Neither of these connectstring are mine. But they do each references two db providers that I want to support in my project...sql and vistadb.
All of that to say...is there a way of determining the run context being used by the designer so that I can add data to an app.config so that it will not break on this error. Or (better) is there a way to force the designer to use my custom app.config. Where is the app.config being used by the designer located?
Thanks for your help in advance.
Seth
Wrap the code that breaks the designer in the Load event in the following:
if ( this.Site == null || !this.Site.DesignMode )
{
... // code that breaks the designer
}

Resources