I'm getting an unusual ArgumentException and I don't know how to fix it.
Message: Parameter is not valid.
Source: "System.Drawing"
TargetSite: {Int32 get_Width()}
StackTrace: at System.Drawing.Image.get_Width()
at System.Drawing.Image.get_Size()
at Telerik.WinControls.Paint.RadGdiGraphics.DrawBitmap(Image image, Int32 x, Int32 y, Double opacity)
at Telerik.WinControls.Paint.RadGdiGraphics.DrawBitmap(Image image, Int32 x, Int32 y)
at Telerik.WinControls.Primitives.ReflectionPrimitive.PaintElement(IGraphics graphics, Single angle, SizeF scale)
at Telerik.WinControls.RadElement.PaintElement(Graphics rawGraphics, IGraphics graphics, Single angle, SizeF scale, Region currentClip)
at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadElement.PaintOverride(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadElement.PaintOverride(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadItem.PaintOverride(IGraphics screenRadGraphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadItem.PaintOverride(IGraphics screenRadGraphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RadItem.PaintOverride(IGraphics screenRadGraphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
at Telerik.WinControls.RootRadElement.Paint(IGraphics graphics, Rectangle clipRectangle)
at Telerik.WinControls.RadControl.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at Telerik.WinControls.RadControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at TrailBlazer.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
The familiar exception window appears when executing the code, however no line is highlighted.
The code which is executing at the time of the exception is the following:
Since the line in red is the only place where System.Drawing is involved, I am inclined to believe that the Telerik WinForms package I'm using is the source of the exception, however I was unable to determine the exact cause. The weird thing is that the same code in Telerik's own example works fine - see attachment. Can anyone please help?
Last edited by obi1kenobi; Jan 1st, 2009 at 03:53 PM.
Reason: Added attachment
Please rate helpful ppl's posts. It's the best 'thank you' you can give
I'm not passing anything directly as you can see from the code above. Actually, since it's get_Width and not set_Width, I think a value is being retrieved...
Please rate helpful ppl's posts. It's the best 'thank you' you can give
What parameter does the ArgumentException indicate is the error? It normally provides this information.
Put a breakpoint on the line you suspect to be causing the exception and see if it is or not.
If the app falls over before this point, then it is not the line you suspect. If it does not, check all the values that are present and see if they are what you anticipate they should be and then step through the code.
i.e. Does the button.Tag property have the correct string file path for your images that you expect it to be? What are the values of res.Width and res.Height, etc.
If the error should lie within these 'Telerik' controls, then I would guess you will have no option to contact them.
I know it's weird but replacing String.IsNullOrEmpty with manual null and zero-length checking really did help. Now the exception only appears when the items are cycled through too quickly. I believe that although String.IsNullOrEmpty was not the direct cause of the exception, it did slow the code down. It may not sound logical at this stage but pls hear me out.
The lack of a highlighted line, together with the peculiar two-buttoned exception window point towards a concurrency-related exception, or at least an exception thrown on a different thread. The carousel is made so that the items which are not shown are not kept in memory, however the items which should enter the control next are stored in memory. So if you cycle through the items quickly enough, not giving the underlying code enough time to catch up, the application will try to dispose of items which have not been created in memory yet. Here comes the issue with the IsNullOrEmpty. My guess is that it would slow the code down (over repeated use, of course) enough to cause this problem.
Anyway, that's my theory and since the control is up and running without problems in reasonable conditions, I'll leave it as it is. Thank you all for your time and effort. Happy hollidays!
Please rate helpful ppl's posts. It's the best 'thank you' you can give
Well I must say that sounds far from satisfactory IMO. I would keep a close eye on that if I were you.
The construct of String.IsNullOrEmpty looks perfectly acceptable to me:
From .NET Reflector:
Code:
public static bool IsNullOrEmpty(string value)
{
if (value != null)
{
return (value.Length == 0);
}
return true;
}
So if you cycle through the items quickly enough, not giving the underlying code enough time to catch up, the application will try to dispose of items which have not been created in memory yet.
Do you create the 'items' yourself? If so, why should your app try to dispose of items that have not been created? At the very least you should be able to check if they are null before disposing of them.
I'm not creating the items, I'm binding a list of filenames to the DataSource property.
Weird thing is, it was working just fine until I rebuilt the project and now it crashes just the same as it did
The only thing I can think of ATM is rewriting the code instead of using the working example code provided by Telerik. I would have considered this much earlier but I'm not too proficient at writing C# code.
Please rate helpful ppl's posts. It's the best 'thank you' you can give
As it seems like the error occurs only under certain circumstances, put a try..catch around the line you suspect to be causing problems, and set a breakpoint inside the catch block: