[Mono-bugs] [Bug 51189][Nor] New - Invalid Cast when tested in .NET 1.1

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 19 Nov 2003 22:04:43 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by rferolino@jaredsoft.com.

http://bugzilla.ximian.com/show_bug.cgi?id=51189

--- shadow/51189	2003-11-19 22:04:43.000000000 -0500
+++ shadow/51189.tmp.11831	2003-11-19 22:04:43.000000000 -0500
@@ -0,0 +1,89 @@
+Bug#: 51189
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: W2K Server
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System.Data
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: rferolino@jaredsoft.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Invalid Cast when tested in .NET 1.1
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+Description of Problem:
+Invalid cast is raised in the ProviderSectionHandler when tested in 
+Microsoft .NET 1.1.
+
+namespace Mono.Data
+{
+	public class ProviderSectionHandler : IConfigurationSectionHandler
+	{
+		public virtual object Create(object parent,object 
+configContext,XmlNode section)
+		{
+			ProviderCollection providers=new ProviderCollection
+();
+			foreach (XmlElement ProviderNode in 
+section.ChildNodes)
+			{
+				Provider provider=new Provider(
+					GetStringValue
+(ProviderNode,"name",true),
+					GetStringValue
+(ProviderNode,"connection",true),
+					GetStringValue
+(ProviderNode,"adapter",true),
+					GetStringValue
+(ProviderNode,"command",true),
+					GetStringValue
+(ProviderNode,"assembly",true),
+					GetStringValue
+(ProviderNode,"description",false));
+				providers.Add(provider);
+			}
+			return providers;
+		}
+
+The foreach(XmlElement ProviderNode in section.ChildNodes) should be coded 
+as "foreach(XmlNode ProviderNode in section.ChildNodes)"  Also because the 
+ProviderNode is an XmlNode, if the NodeType is not an XmlElement the 
+GetStringValue method would fail.  In my test, it failed when the NodeType 
+is a Whitespace; therefore, a guard check is necessary in that section. 
+Something like:
+
+if(ProviderNode.NodeType == XmlNodeType.Element)
+{
+   Provider provider=new Provider(
+	GetStringValue(ProviderNode,"name",true),
+   ......
+}
+
+Steps to reproduce the problem:
+1. Create a project Mono.Data in Visual studio
+2. Compile the project as class library (Mono.Data)
+3. Create a client project that would use the Mono.Data
+In the Main() method have a line:
+ProviderCollection providers = (ProviderCollection) 
+ConfigurationSettings.GetConfig("mono.data/providers");
+
+Actual Results:
+An unhandled exception of 
+type 'System.Configuration.ConfigurationException' occurred in system.dll
+
+Expected Results:
+The providers field should have all providers defined in App.Config
+
+How often does this happen? 
+All the time.
+
+Additional Information:
+To get the Invalid Cast decorate the internal of ProviderSectionHandler 
+with a try/catch block.