diff --git a/XmlSchemaClassGenerator.Tests/xsd/simple/simple.xsd b/XmlSchemaClassGenerator.Tests/xsd/simple/simple.xsd
index fdc941b2..a616bcb8 100644
--- a/XmlSchemaClassGenerator.Tests/xsd/simple/simple.xsd
+++ b/XmlSchemaClassGenerator.Tests/xsd/simple/simple.xsd
@@ -20,6 +20,7 @@
+
diff --git a/XmlSchemaClassGenerator/TypeModel.cs b/XmlSchemaClassGenerator/TypeModel.cs
index 9fa43b47..af2cf882 100644
--- a/XmlSchemaClassGenerator/TypeModel.cs
+++ b/XmlSchemaClassGenerator/TypeModel.cs
@@ -1281,6 +1281,22 @@ public override CodeExpression GetDefaultValueFor(string defaultString, bool att
else
return new CodePrimitiveExpression(Convert.ChangeType(defaultString, ValueType));
}
+ else if(type == typeof(byte[]) && !string.IsNullOrWhiteSpace(defaultString))
+ {
+ int numberChars = defaultString.Length;
+ if(numberChars % 2 == 1)
+ throw new NotSupportedException(string.Format("Default value {0} is not a valid hexBinary value.", defaultString));
+
+ var byteValues = new CodePrimitiveExpression[numberChars / 2];
+ for (int i = 0; i < numberChars; i += 2)
+ byteValues[i / 2] = new CodePrimitiveExpression(Convert.ToByte(defaultString.Substring(i, 2), 16));
+
+ // For whatever reason, CodeDom will not generate a semicolon for the assignment statement if CodeArrayCreateExpression
+ // is used alone. Casting the value to the same type to work around this issue.
+ var rv = new CodeCastExpression(typeof(byte[]), new CodeArrayCreateExpression(typeof(byte), byteValues));
+ return rv;
+
+ }
return new CodePrimitiveExpression(Convert.ChangeType(defaultString, ValueType, CultureInfo.InvariantCulture));
}