Explorar o código

2007-10-10 Marek Habersack <[email protected]>

	* TemplateControlCompiler.cs: be careful when using type
	converters taken from attributes attached to class members. They
	may come from the System.Design namespace, which is mostly not
	implemented on Mono.

svn path=/trunk/mcs/; revision=87255
Marek Habersack %!s(int64=18) %!d(string=hai) anos
pai
achega
66836ec00e

+ 7 - 0
mcs/class/System.Web/System.Web.Compilation/ChangeLog

@@ -1,3 +1,10 @@
+2007-10-10  Marek Habersack  <[email protected]>
+
+	* TemplateControlCompiler.cs: be careful when using type
+	converters taken from attributes attached to class members. They
+	may come from the System.Design namespace, which is mostly not
+	implemented on Mono.
+
 2007-10-01  Marek Habersack  <[email protected]>
 
 	* AppResourcesCompiler.cs: resources are no longer compiled into a

+ 21 - 3
mcs/class/System.Web/System.Web.Compilation/TemplateControlCompiler.cs

@@ -1618,11 +1618,29 @@ namespace System.Web.Compilation
 			return inst;
 #endif
 		}
+
+		bool SafeCanConvertFrom (Type type, TypeConverter cvt)
+		{
+			try {
+				return cvt.CanConvertFrom (type);
+			} catch (NotImplementedException) {
+				return false;
+			}
+		}
+
+		bool SafeCanConvertTo (Type type, TypeConverter cvt)
+		{
+			try {
+				return cvt.CanConvertTo (type);
+			} catch (NotImplementedException) {
+				return false;
+			}
+		}
 		
 		CodeExpression GetExpressionFromString (Type type, string str, MemberInfo member)
 		{
 			TypeConverter cvt = GetConverterForMember (member);
-			if (cvt != null && !cvt.CanConvertFrom (typeof (string)))
+			if (cvt != null && !SafeCanConvertFrom (typeof (string), cvt))
 				cvt = null;
 
 			object convertedFromAttr = null;
@@ -1775,10 +1793,10 @@ namespace System.Web.Compilation
 				wasNullable ? TypeDescriptor.GetConverter (type) :
 				TypeDescriptor.GetProperties (member.DeclaringType) [member.Name].Converter;
 
-			if (preConverted || (converter != null && converter.CanConvertFrom (typeof (string)))) {
+			if (preConverted || (converter != null && SafeCanConvertFrom (typeof (string), converter))) {
 				object value = preConverted ? convertedFromAttr : converter.ConvertFromInvariantString (str);
 
-				if (converter.CanConvertTo (typeof (InstanceDescriptor))) {
+				if (SafeCanConvertTo (typeof (InstanceDescriptor), converter)) {
 					InstanceDescriptor idesc = (InstanceDescriptor) converter.ConvertTo (value, typeof(InstanceDescriptor));
 					if (wasNullable)
 						return CreateNullableExpression (originalType, GenerateInstance (idesc, true),