I have a DataGridView that displays a list of MMS Messages. To differentiate between sent and received, I put a right arrow and left arrow in a column. Our customer loved it, but wants the right arrow to be green for even more clarity, especially in international environments.
I took the right arrow and opened it in Visual Studio 2003 (I am using VS2010 for writing the application). I recolored the icon and it looked great, however when I went to display the containing Control, I get the following error:
The following exception occurred in the DataGridView:
System.ArgumentException: Parameter is not valid.
at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at System.Drawing.ImageConverter.convertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
at System.Windows.Forms.Formatter.FormatObjectInternal(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue, Object dataSourceNullValue)
at System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle& cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
To replace this default dialog please handle the DataError event.
When I create the DataTable to be populated with the data, I use this on the column that will have the icon
dt.Columns.Add(sDirection);
dt.Columns[sDirection].DataType = typeof(Byte[]);
When I add the data to the rows, I have a method to convert the Icon.
internal static Byte[] ConvertIconToByteArray(Icon pIcon) {
MemoryStream ms = new MemoryStream();
pIcon.Save(ms);
return (ms.GetBuffer());
}
And I add the DataTable to the DataGridView with
grdMMSList.DataSource = dt.DefaultView;
(Method calls removed from the above code for clarity)
I followed through in the debugger, and setting the DefaultView as the DataSource is where the error is getting thrown. I tried placing it in a try/catch block so I could see the Exception, but it doesn't trigger the catch.
Just a few other bits of information:
- The icon is stored as a Resource and is called by Properties.Resources.RightArrow
- After changing the colors, I just Save the file in VS2003, nothing with a Save As. The file still shows up as an Icon everywhere.
- Back in VS2010, the Resource File does have the new color scheme and renders properly there.
Thank you in advance for any help you can provide.
I would not edit the images this way. If you want a valid set of arrows that are all supported for addition into a DataGridView, so to the directory
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\VS2010ImageLibrary\1033
here you will find a .zip file. Unzip it.
Then you will find varios subdirectories with loads of MS icon and images etc. Navigate to
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\VS2010ImageLibrary\1033
\VS2010ImageLibrary\VS2010ImageLibrary\Objects\png_format\WinVista
here you will find all different kinds of arrows in all different colours. My advice is use these, not your bitmap edits to existing files.
I hope this helps.
Related
I'm trying to build a simple custom SSIS component which looks at a single input column and validates it, creating an output column of type bool depending on the value of each row.
I've successfully built an even simpler component that takes a value and transforms it: that doesn't require fiddling with the output columns. In this instance I need to take in a string and output a boolean and the component needs to know that it outputs a boolean so I can feed the value into a conditional split.
I'm struggling to add the output columns. Based on code samples from Microsoft, I have done this:
public override DTSValidationStatus Validate()
{
IDTSOutput100 output = ComponentMetaData.OutputCollection[0];
IDTSOutputColumn100 outputcol = output.OutputColumnCollection.New();
outputcol.Name = "IsValid";
outputcol.SetDataTypeProperties(DataType.DT_BOOL, 0, 0, 0, 0);
return DTSValidationStatus.VS_ISVALID;
}
And then I attempt to populate it during the ProcessInput step:
public override void ProcessInput(int inputID, PipelineBuffer buffer)
{
while (buffer.NextRow())
{
string str = buffer.GetString(0);
buffer.SetBoolean(0, IsValid(str)); // validation code not relevant
}
}
When I try to use this component in the package, I get this error:
The component has detected potential metadata corruption during validation.
Error at Data Flow Task [Uppercase [24]]: System.MissingMethodException: Method not found: 'Void Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSOutputColumn100.SetDataTypeProperties(Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType, Int32, Int32, Int32, Int32)'.
at EmailValidation.Uppercase.Validate()
at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostValidate(IDTSManagedComponentWrapper100 wrapper)
Searching on this error message has yielded nothing of value.
In the original sample - and some other tutorials online - adding output columns is done by looping through the input column and adding an additional output for each. I have tried this and get the same error.
I have also tried moving the output column code from Validate to OnInputPathAttached which still yields the same error.
What am I doing wrong?
On investigation this appears to be a bug in SQL Server Data Tools for Visual Studio 2015. I have built, deployed and used a custom component with customised output columns in an Integration Services package in Visual Studio 2013. However, the same tool deployed in a package in 2015 causes the error described.
In case it's still relevant, I encountered a similar issue (With the ComponentMetaData property rather than SetDataTypeProperties), and the solution that worked for me was setting the Embed Interop Types property of the Microsoft.SqlServer.DTSPipelineWrap and Microsoft.SQLServer.DTSRuntimeWrap references to false.
I found this solution here. It's listed as a solution for getting an InvalidCastException, but it seems relevant for whenever you're referencing the DTSPipelineWrap or the DTSRuntimeWrap assemblies in custom components.
I looked extensively online but I couldn't find anything really specific to help me out in this trouble I am having.
I am trying to make a custom renderer for a Button component, in Xamarin forms. Why am I not using the XLabs ImageButton component? Because it's not compatible with Android 4.0.3, which is my current Android target version.
I also tried writing on my own some code that is that much worthless that I am quite shy to post, unless you really require me to :)
I am in need of this code because, without it, images just fail to load in buttons while trying to use them in any button like this:
<Button Image="someImage.png"/>
I tried following a tutorial, here:
http://blog.falafel.com/learning-xamarin-custom-renderers-in-xamarin-forms/
But I failed adapting it to my needs.
Are no images being displayed at all? Check your locations of the images. Default location in ios is Resources folder, in android it is resources/drawable and in wp it is the root. If you want one image rather than 3 for each solution, put in to the PCL and set the build property to embedded resource and qualify the name with the namespace it is in. ie... ProjectName.Assets.image.png if it is in the PCL Assets directory. Not sure if this is your problem or not, but figured I would offer it up , just in case.
You can solve this by making an Image tap-able using TapGestureRecognizer. For implementation, go through this: http://www.c-sharpcorner.com/UploadFile/e04e9a/xamarin-forms-image-button-recipe/
The proper way to do this is described in Chapter 13 of Charles Petzold's excellent book on Xamarin Forms: https://developer.xamarin.com/guides/xamarin-forms/creating-mobile-apps-xamarin-forms/
My approach to this problem is (different than the book) to use a converter for the image file path. The Button.Image property is a FileImageSource object and it wants a file path. Unfortunately you cannot use embedded resources or a content file in the PCL. You must add an individual image file in each of the iOS, Android and UWP projects. The way I do this is to add the image to the PCL and use linking (option on the add existing file dialog).
So here is my converter approach to the above issue
<Button Image="{Binding Converter={StaticResource FileImageSourceConverter}, ConverterParameter=someImage.png}" />
The static resource...
<ContentPage.Resources>
<ResourceDictionary>
<local:FileImageSourceConverter x:Key="FileImageSourceConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
The converter...
public class FileImageSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string filename = parameter as string;
switch(Device.RuntimePlatform)
{
case Device.iOS:
case Device.Android:
default:
return filename;
case Device.Windows:
return Path.Combine("Images", filename);
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
The advantages of this approach is that (1) your XAML is not cluttered up with OnPlatform elements; (2) you don't need to put your images in the root directory of the UWP project; (3) much simpler than using a custom render to solve the same problem as some have suggested.
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.
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"
I'm creating a PowerPoint AddIn, which is supposed to read information from an external file and integrate that information into the current slide which contains shapes, mostly textbox shapes and connector shapes connecting the text boxes. Each connector is located within a group, containing the connector shape and a textbox, with acts as a label for the connector. The following image depicts this scenario.
My task at hand involves accessing properties of connector shapes contained within groups as described above, namely BeginConnectedShape and EndConnectedShape. Here's some code which is supposed to do just that:
Shape groupShape = Globals.ThisAddIn.Application.ActiveWindow.Selection.ShapeRange[1];
//check if groupshape actually is a group
if (groupShape.Type == Microsoft.Office.Core.MsoShapeType.msoGroup) {
//iterate over all elements within groupShape
foreach (Shape childShape in groupShape.GroupItems)
{
if (childShape.Connector == Microsoft.Office.Core.MsoTriState.msoTrue)
{
//if the shape is a connector, retrieve source and target of the connector
Shape source = childShape.ConnectorFormat.BeginConnectedShape;
Shape target = childShape.ConnectorFormat.EndConnectedShape;
//Do something with source and target.
}
}
}
Running this code while having a group containing a properly connected connector shape (that is, both ends are connected to anchor points of other shapes) selected yields the following exception.
System.Runtime.InteropServices.COMException wurde nicht von Benutzercode behandelt.
HResult=-2147418113
Message=Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
Source=HandoverAddin
ErrorCode=-2147418113
StackTrace:
at Microsoft.Office.Interop.PowerPoint.ConnectorFormat.get_BeginConnectedShape()
at MyAddin.Ribbon.button1_Click(Object sender, RibbonControlEventArgs e) in Ribbon.cs:line 56
at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ControlActionRaise(IRibbonControl control)
at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ButtonClickCallback(RibbonComponentImpl component, Object[] args)
at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.Invoke(RibbonComponentCallback callback, Object[] args)
at Microsoft.Office.Tools.Ribbon.RibbonMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.System.Reflection.IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
InnerException:
This exception is raised when executing childShape.ConnectorFormat.BeginConnectedShape. childShape.ConnectorFormat.EndConnectedShape raises this exception as well. Other operations within ConnectorFormat work fine (i.e. BeginDisconnect successfully disconnects the start of the connector).
shape.ConnectorFormat.BeginConnectedShape works fine, if the connector is not contained within a group. In my case tough, connectors and associated labels have to be grouped together.
I've also observed that accessing BeginConnectedShape on a connector with a disconnected start raises an UnauthorizedAccessException, regardless of whether that connector is contained within a group or not. This seems to be expected behavior.
The exception listed above seems to be some sort of internal exception which is not supposed to get raised under normal circumstances. Therefore, I've checked for any available updates, but none were found for Office 2010 and Visual Studio 2010 Professional.
Any help, possible fixes or workarounds on this issue are greatly appreciated.
Edit: Implementing the same functionality using VBA also results in an error with code 8000FFFF (same as above).
Here's a crude VBA version of this that might help:
It's essentially the same as yours, I think, except for the added test:
If osh.Connector
Without that, it raised errors because it's looking at each shape in the group, but only the connector has the .ConnectorFormat and its associated properties.
Dim groupshape As Shape
Dim oSh As Shape
Dim oBgnShape As Shape
Dim oEndShape As Shape
Set groupshape = ActiveWindow.Selection.ShapeRange(1)
If groupshape.Type = msoGroup Then
For Each oSh In groupshape.GroupItems
**If oSh.Connector Then**
Set oBgnShape = oSh.ConnectorFormat.BeginConnectedShape
Debug.Print oBgnShape.Left
Set oEndShape = oSh.ConnectorFormat.EndConnectedShape
End If
Next
End If