c# extended control in designer - c#

I extended a control like so
public partial class NewControl : OriginalControl
{
public NewControl()
{
}
}
and changed these lines in the MyForm.Designer.cs from
private OriginalControl control1;
this.control1 = new OriginalControl();
to
private NewControl control1;
this.control1 = new NewControl();
How ever when I open my form in designer I get this error:
Failed to load designer. Check the source code for syntax errors and
check if all references are available.
ICSharpCode.FormsDesigner.FormsDesignerLoadException:
System.ComponentModel.Design.Serialization.CodeDomSerializerException:
Could not find type 'NewControl'. Please make sure that the assembly
that contains this type is referenced. If this type is a part of your
development project, make sure that the project has been successfully
built using settings for your current platform or Any CPU. at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager
manager, String exceptionText, String helpLink) at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager
manager, String name, CodeExpression expression) at
System.ComponentModel.Design.Serialization.CodeDomSerializer.DeserializeStatementToInstance(IDesignerSerializationManager
manager, CodeStatement statement) at
System.ComponentModel.Design.Serialization.CodeDomSerializer.Deserialize(IDesignerSerializationManager
manager, Object codeObject) at
ICSharpCode.FormsDesigner.Services.ProjectResourcesComponentCodeDomSerializer.Deserialize(IDesignerSerializationManager
manager, Object codeObject) at
System.Windows.Forms.Design.ControlCodeDomSerializer.Deserialize(IDesignerSerializationManager
manager, Object codeObject) at
ICSharpCode.FormsDesigner.Services.ProjectResourcesComponentCodeDomSerializer.Deserialize(IDesignerSerializationManager
manager, Object codeObject) at
System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.DeserializeName(IDesignerSerializationManager
manager, String name, CodeStatementCollection statements)
System.ComponentModel.Design.Serialization.CodeDomSerializerException:
The variable 'control1' is either undeclared or was never
assigned. at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager
manager, String exceptionText, String helpLink) at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager
manager, String name, CodeExpression expression) at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager
manager, String name, CodeExpression expression) at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager
manager, CodeStatement statement)
at
ICSharpCode.FormsDesigner.FormsDesignerViewContent.LoadDesigner()
at
ICSharpCode.FormsDesigner.FormsDesignerViewContent.LoadAndDisplayDesigner()
at
ICSharpCode.FormsDesigner.FormsDesignerViewContent.LoadInternal(OpenedFile
file, Stream stream) at
ICSharpCode.SharpDevelop.Gui.AbstractViewContentHandlingLoadErrors.Load(OpenedFile
file, Stream stream)
How am I extending my control wrong?

This may purely be an issue with the namespaces in which these two controls appear. See if a fully qualified class name happens to solve you issue.

Related

Ribbon. The value cannot be null. Parameter name: obj

I am adding Ribbon.
Instead of Ribbon, I am getting error.
Error:
The value cannot be null. Parameter name: obj
at Microsoft.Internal.VisualStudio.PlatformUI.Utilities.GetObjectData (IVsUIObject obj)
at Microsoft.VisualStudio.Tools.Office.Ribbon.ImageHelper.GetImageFromMoniker (ImageMoniker moniker, Size ImgSize, Int32 dpi, Nullable`1 backgroundColor)
at Microsoft.VisualStudio.Tools.Office.Ribbon.View.Themes.Office15Theme.GetFileMenuImage (Boolean hover, Boolean opened, Control control)
at Microsoft.VisualStudio.Tools.Office.Ribbon.View.Themes.OfficeTheme.GetFileMenuSize (Control control)
at Microsoft.VisualStudio.Tools.Office.Ribbon.View.RibbonView.InitializeComponent ()
at Microsoft.VisualStudio.Tools.Office.Ribbon.View.RibbonView.set_Site (ISite value)
at System.ComponentModel.Container.Add (IComponent component, String name)
at System.ComponentModel.Design.DesignerHost.PerformAdd (IComponent component, String name)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent (Type componentType, String name)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance (Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance (Type type, ICollection arguments, String name, Boolean addToContainer)
at Microsoft.VisualStudio.Tools.Office.Serialization.TypeResolutionModifications.VSTDesignerSerializationManager.CreateInstance (Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize (IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at Microsoft.VisualStudio.Tools.Office.Ribbon.Serialization.RibbonTypeCodeDomSerializer.Deserialize (IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad (IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad (IDesignerSerializationManager serializationManager)
--- End of the stack trace from the previous location where the exception was thrown ---
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad (IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted (Int32 fReload)
Description.
I want to create an Excel Addin.
I created a project.
I am adding Ribbon.
An error is displayed instead of Ribon.
Question.
Why is there an error?
How to fix the error "The value cannot be null. Parameter name: obj"?
Used.
Wni - 7x64;
Visual Studio - 2019 Community.
Picture1.
Picture2.
Picture3.
Update-1.
Opened a project in Visual Studio-2017 Community.
Ribbon opens.
Question.
Why won't Ribbon open in Visual Studio-2019 Community?
Picture-4
Update-2
I made a right click - > I chose "Build".
Visual Studio has completed the "Build".
Visual Studio added a file to the Solution - ExcelAddInTest_04_TemporaryKey.pfx.
I added a Ribbon.
Result: Error.
The value cannot be undefined. Parameter name: obj
in Microsoft. Internal.VisualStudio.PlatformUI.Utilities.GetObjectData(IVsUIObject obj)
in Microsoft. VisualStudio.Tools.Office.Ribbon.ImageHelper.GetImageFromMoniker(ImageMoniker moniker, Size ImgSize, Int32 dpi, Nullable`1 backgroundColor)
in Microsoft. VisualStudio.Tools.Office.Ribbon.View.Themes.Office15Theme.GetFileMenuImage(Boolean hover, Boolean opened, Control control)
in Microsoft. VisualStudio.Tools.Office.Ribbon.View.Themes.OfficeTheme.GetFileMenuSize(Control control)
in Microsoft. VisualStudio.Tools.Office.Ribbon.View.RibbonView.InitializeComponent()
in Microsoft. VisualStudio.Tools.Office.Ribbon.View.RibbonView.set_Site(ISite value)
in System.ComponentModel.Container.Add(IComponent component, String name)
in System.ComponentModel.Design.DesignerHost.PerformAdd(IComponent component, String name)
in System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(Type componentType, String name)
in System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
in System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
in Microsoft. VisualStudio.Tools.Office.Serialization.TypeResolutionModifications.VSTDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
in System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
in Microsoft. VisualStudio.Tools.Office.Ribbon.Serialization.RibbonTypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
in System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
in Microsoft. VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
--- End of the stack trace from the previous location where the exception occurred ---
in Microsoft. VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
in Microsoft. VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
Picture-1
Picture-2
Picture-3
Update-3.
I moved to Visual Studio-2017.
I created an add-on (project-1).
I added a Ribbon.
Ribbon is displayed.
I moved to Visual Studio-2019.
I opened a previously created add-in (project-1).
I opened the Ribbon.
Ribbon is not displayed. I get an error.
I started debugging (F5).
I opened an Excel file.
Result: Ribbon is displayed in Excel.

C# - System.OutOfMemoryException in Visual Studio

I have a problem, when I right click my main form in Visual Studio and go to 'View Designer' I get an error. It says: 'Exception of type 'System.OutOfMemoryException' was thrown.'
Stacktrace:
at System.Reflection.AssemblyName.nGetFileInformation(String s)
at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_AssemblyName()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_FullName()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.AssemblyEntry.get_AssemblySpec()
at Microsoft.VisualStudio.Design.VSTypeResolutionService.SearchProjectEntries(String fullName, Boolean correctThread)
at Microsoft.VisualStudio.Design.VSTypeResolutionService.System.ComponentModel.Design.IDesignTimeAssemblyLoader.GetTargetAssemblyPath(AssemblyName runtimeOrTargetAssemblyName, String suggestedAssemblyPath, FrameworkName targetFramework)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUniverse.ResolveAssembly(AssemblyName assemblyName, Assembly runtimeAssembly)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUniverse.GetTypeFromTargetLocation(Type type, Boolean validateBase)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUniverse.GetType(Type type)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetCustomAttributes(Type type, Type filter, Boolean inherit, CustomAttributesCache cache)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkType.GetCustomAttributes(Type filter, Boolean inherit)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkAttributeCollection.GetAttributes(Type type, Type filter)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkAttributeCollection.GetAttributes(MemberInfo member, Type filter)
at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkAttributeCollection.get_Attributes()
at System.ComponentModel.AttributeCollection.get_Count()
at Microsoft.VisualStudio.Design.VSDesignSurface.EnsureExtensions(IComponent component)
at Microsoft.VisualStudio.Design.VSDesignSurface.CreateInstance(Type type)
at System.ComponentModel.Design.DesignerHost.System.ComponentModel.Design.IDesignerHost.CreateComponent(Type componentType, String name)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.DesignerSerializationManager.System.ComponentModel.Design.Serialization.IDesignerSerializationManager.CreateInstance(Type type, ICollection arguments, String name, Boolean addToContainer)
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)
Designer:
http://pastebin.com/hdRB5DAj
I got this error this morning, but I still haven't resolved it. If anyone could help me I would really appreciate it!
I'm only using ~55% of all my RAM, so that can't be it.
As Dr Hebie points out, it's doubtful that it's VS itself throwing the OOM exception, but something in your form constructor.
A Technique I've used to great success with this is opening the form code and inserting Throw new Exception("Message describing position") at the start of the constructor. Hopefully, now instead of getting an OOM exception, you'll get the exception you just specified. Now move this exception around until you get the OOM exception. This will show you the line of code that is causing the OOM.
Good luck!
There are multiple things that this can be caused by, and the problem gets worse with older version of Visual Studio (2005 was particularly bad in my experience).
As this is happening when you view the designer of a form, there is a chance that this is due to objects being created in your form's constructor or event handlers. When VS loads your form into the designer it will actually compile and create an instance of the form class. Any objects you create within the form are likely to get created at this time as well. All this happens within Visual Studio's memory allocation so if you are allocating a large amount of memory this can hinder Visual Studio's memory handling.
I would suggest you perform a check on the DesignMode property of the form and only load/create instances of data classes (like Views) when that property is false. You should also be prepared to do this in event handlers throughout the form as these can be fired by the Visual Studio designer.
Alternatively, if you're feeling brave, you can actually debug Visual Studio with itself! Open your project in VS and then open another instance of VS. In the second instance use the Debug -> Attach to Process option and attach to the first VS instance. Now open the designer for your form and see if you can identify where the error occurs. You may have to switch on the 'break on thrown exceptions' settings under Debug -> Exceptions in the second VS instance to ensure your debugging session sees all exceptions.
Good Luck.

Editing custom SSIS PipelinComponent throws error "value of 'null' is not valid for 'stream'"

I created a custom PipelineComponent to convert data to Proper Case, like so:
[DtsPipelineComponent(DisplayName = "ProperCase")]
public class ProperCaseTransform : PipelineComponent
{
//irrelevant code here
}
However, when I add this component to my data flow, and click "edit", I am met with with following error:
Value of 'null' is not valid for 'stream'. (Microsoft Visual Studio)
Program Location:
at System.Drawing.Icon..ctor(Stream stream, Int32 width, Int32 height)
at System.Drawing.Icon..ctor(Stream stream, Size size)
at Microsoft.SqlServer.IntegrationServices.Designer.Common.ImageSourceHelper.GetIconFromResource(Assembly assembly, String resourceName, Boolean isLarge)
at Microsoft.DataTransformationServices.Design.DesignUtils.ExtractManagedBitmap(String fileName, String resName, Boolean large)
at Microsoft.DataTransformationServices.Design.DesignUtils.ExtractBitmap(String fileName, String iconResource, Boolean isNative, Boolean large)
at Microsoft.DataTransformationServices.Design.PipelineUtils.GetComponentIcon(IDTSComponentMetaData100 componentMetadata, IServiceProvider serviceProvider)
at Microsoft.DataTransformationServices.Design.FunctionLevelMappingUI..ctor(FunctionLevelComponentUI componentUI, IUserPromptService promptService)
at Microsoft.DataTransformationServices.Design.FunctionLevelComponentUI.EditImpl(IWin32Window parentControl)
at Microsoft.DataTransformationServices.Design.DtsComponentUI.Edit(IWin32Window parentWindow, Variables variables, Connections connections)
I have seen similar problems happening with Visual Studio 2012 (apparently CU4 for SP1 fixes this), but never for VS 2013. How can I fix this issue? My component is unusable with editing.
I was tipped off by this question: error : Value of 'null' is not valid for 'stream'. Although this is clearly a bug in the IDE, it was possible to fix by adding an icon to my custom component:
[DtsPipelineComponent(DisplayName = "ProperCase", IconResource="MyNamespace.app.ico")]
public class ProperCaseTransform : PipelineComponent
{
//irrelevant code here
}
I then included a random icon file in the dll (named app.ico), set the build action to "Embedded Resource", and recompiled; which fixed the issue in visual studio.
NOTE: the IconResource value has the format:
[ProjectNamespace] + "." + "Folder path separated by dots" + "." + "iconName.ico"
The project namespace is defined in the project properties.
Example: the icon MyIcon.ico in the folder icons in a project with namespace MyProject would have the icon resource value "MyProject.Icons.MyIcon.ico"

How do I store a custom class from within the same assembly in application settings?

I have a very simple class
public class Preferences
{
public bool RepeatInfinite { get; set; }
public int RepeatCount { get; set; }
}
If I put this class in another assembly it shows up in the Settings tab when you browse for the type. If I however put this class in the same assembly as the running program, I can't see it or browse for it. What's going on here?
I've had the same problem and it's quite annoying. To work around it I do the following.
Create the setting and type it to Object
Open the settings file in notepad
Change the type to the name of the type in the same assembly (fully qualified name)
Reopen the designer.
Make an innocuous change, hit save and the C# file gets regenerated with your type.

Get executing assembly name from referenced DLL in C#

What is the best way to get the application name (i.e MyApplication.exe) of the executing assembly from a referenced class library in C#?
I need to open the application's app.config to retrieve some appSettings variables for the referenced DLL.
To get the answer to the question title:
// Full-name, e.g. MyApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
string exeAssembly = Assembly.GetEntryAssembly().FullName;
// or just the "assembly name" part (e.g. "MyApplication")
string exeAssemblyName = Assembly.GetEntryAssembly().GetName().Name;
As mentioned by #Ben, since you mention wanting to get the configuration information, use the ConfigurationManager class.
If you want to get the current appdomain's config file, then all you need to do is:
ConfigurationManager.AppSettings....
(this requires a reference to System.Configuration of course).
To answer your question, you can do it as Ray said (or use Assembly.GetExecutingAssembly().FullName) but I think the problem is easier solved using ConfigurationManager.
To get the exact name without versions, etc. use:
string appName = Assembly.GetEntryAssembly().GetName().Name;
Works with .NET v1.1 and later.
You can get the assembly through the class type...
typeof(MyClass).Assembly
If you want the name of the parent EXE and not the referenced DLL assembly - you will need to use this:
Assembly.GetEntryAssembly().GetName().Name
This will return the EXE name (minus the .EXE part).
Using GetExecutingAssembly() is not right as per the OP's question (first paragraph of it!) as it will return the DLL name.
You should never couple your libraries to a consumer (in this case Web, WinForm or WCF app). If your library needs configuration settings, then GIVE it to the library.
Don't code the library to pull that data from a consumer's config file. Provide overloaded constructors for this (that's what they are for).
If you've ever looked at the ConfigurationManager.AppSettings object, it is simply a NameValueCollection. So create a constructor in your library to accept a NameValueCollection and have your consumer GIVE that data to the library.
//Library
public class MyComponent
{
//Constructor
public MyComponent(NameValueCollection settings)
{
//do something with your settings now, like assign to a local collection
}
}
//Consumer
class Program
{
static void Main(string[] args)
{
MyComponent component = new MyComponent(ConfigurationManager.AppSettings);
}
}
If you want to read (and display) version number:
Assembly ass = System.Reflection.Assembly.GetExecutingAssembly();
AssemblyName assname = ass.GetName();
Version ver=assname.Version;
Somewhere in application (ie Title block in a Windows form)
this.Text = "Your title Version " + ver;
For the short name of an assembly from a class instance:
Me.GetType ().Assembly.GetName().Name

Categories