April 20, 2010

SqlCeException Unspecified error [ 655360 ]

Filed under: Uncategorized — Tags: , — yasi8h @ 12:44 pm

I spend a fair amount of time searching the net for this. All because i couldn’t notice the Native Error: 25101 in the exception.

SQL Server Compact has exceeded the buffer size. The default size can be increased on initialization by modifying the ssce: max buffer size property.


max buffer size
The largest amount of memory, in kilobytes, that SQL Server Mobile can use before it starts flushing changes to disk. If not specified, the default value is 640.

You can try increasing your buffer size.

conn.ConnectionString =
“Persist Security Info = False; Data Source = ‘SalesData.sdf’;” +
“Password = ‘
‘; File Mode = ‘shared read’; ” +
“Max Database Size = 256; Max Buffer Size = 1024”;


January 4, 2010

Validation Frameworks for .net Compact Framework

Filed under: Uncategorized — Tags: , — yasi8h @ 6:52 am

If you google the title of this post you would not find any satisfying results. I tried it and i didn’t (.net validation framework intends to support the .net compact framework. But this is still in the todo list) came across any validation framework that officially supports .net CF. But most of .net validation frameworks out there or at least certain parts of the frameworks can be used in a .net cf project. I had to do some research on this topic recently so i am writing down my finding here. Please note that this post is by no means perfect. I might have missed some validation frameworks intentionally or accidentally. I was interested in a framework that would provide a basic validation framework and some ‘bindings’/helpers for windows forms and MVC. I needed a framework that can be used in a web/desktop and a mobile application. Any framework that was heavily coupled with any one of the platforms was ignored (as it will be difficult to use them in the other platforms).

Validation Frameworks ‘Assessed’

.net Validation Framework

  • The main ValidationFramework.dll assembly works with .netcf 3.5
  • validation rules can be specified as attributes, runtime code and xml configuration. so for whatever validation you need to do, you can use a exsisting rule or you can write a new one.
    • Attributes
      • As you would expect you can specify attributes that specify one or more rules to be applied on a given field, property or (method) parameter.
    • Runtime Code
      • You could write some code to specify what rules needs to be applied to what members. This code can be invoked at the runtime. This code will use types given in ValidationFramework.Reflection namespace to get the relavant members of a given type through reflection. After which you can add validation rules to those members.
    • XML
      • Validation definitions can be defined using XML configuration. The mapping document is designed to be readable and hand-editable.
        • <?xml version=”1.0″ encoding=”utf-8″ ?> <validationMapping xmlns=”urn:validationFramework-validationDefinition-1.5″> <class typeName=”ValidationSample.Person, ValidationSample”><property name=”Name”> <rule typeName=”RequiredStringRule” initialValue=”aaaa”/> </property> <property name=”Age”> <rule typeName=”RangeRule” minimum=”18″ maximum=”80″errorMessage=”Age is invalid” /> </property> <method name=”SetTheAge”> <overloadType typeName=”System.Int32″/> <parameter name=”age”> <rule typeName=”RangeRule” minimum=”18″ maximum=”80″ errorMessage=”Age is invalid” /> </parameter> </method> </class> </validationMapping>
  • Actual validating of a object is done one of the two ways noted bellow.
    • Inside validation
      • This is when the class is aware of validation and does the validation her self. this can be done by inheriting this class from one of the provided base classes and using the inherited methods (such as NotifyValidateChange method, which validate and then do a NotifyChange as in INotifyPropertyChange interface implementations).
      • Another way of doing this is by using a FieldValidationManager or a PropertyValidationManager internally within the class.
    • Outside validation
      • When outside validation is done the class whose objects are validated doesn’t know about the validation process and does not invoke it. someone can externally use a FieldValidationManager or a PropertyValidationManager to do the validation.
  • Validation Rules can be grouped using RuleSets
  • All the Validate methods in *ValidationManagers and Validation related base classes return a ValidationResult.
  • If you decide to write your biznuess classes inheriting from a provided base class that implements IDataErrorInfoProvider interface you can use windows forms controls like ErrorProvider to display errors in windows forms projects.
  • The framework also provides types to help you implement validation in WPF and Web projects.
  • Although the framework have some documentation including the on site wiki, QuickStart projects, FAQ and a help file with documantaion for all the types and there members in the framework. There is a lack of a getting started guide.

Validation Application Block

  • Has better documentation when compared to .net Validation Framework.
  • Just as the .net Validation Framework, Validation Application Block (from here onwards reffered to as VAB) has three ways to specify validation rules or validators.
    • Attributes
    • Runtime Code
    • XML
  • “can be integrated with ASP.NET, Windows Forms, and Windows Communications Foundation (WCF).”
  • Depends on
    • Core library functionality: Microsoft.Practices.EnterpriseLibrary.Common.dll
    • The ObjectBuilder subsystem: Microsoft.Practices.ObjectBuilder.dll
  • When editing the XML configuration for the validation block you can use the provided enterprice library configuration editor(s). This configuration file can contain validation details for types.
  • Validation Rules can be grouped using RuleSets.
  • Validation is done in a manner similler to .net validation framework (or the other way around). ValidationResults class is used to send out validation results…etc
  • Has “Self Validation”. Which basically lets a class mark it self as self validatable and then when the class is validated a specified (by the class it self) method (inside the class) will be run. This method would receive a ValidatinResults type instance which should be modified with the appopriate results.
  • Self Validation and ‘normal’ validation (other validators provided by the framework) can be used together.
  • Validation of a object is done like:
    • Customer customer = new Customer(); ValidationResults results = Validation.Validate<Customer>(customer, customerRuleSetCombo.Text);
    • Or
    • Customer customer = new Customer(); Validator<Customer> validator = ValidationFactory.CreateValidator<Customer>(customerRuleSetCombo.Text); ValidationResults results = validator.Validate(customer);
  • Provides integration support for Win Forms. The main point of integration is ValidationProvider class. It is an Extender ( control that adds properties (at design time) to controls. So if you have a form for adding a new customer you can have a ValidationProvider component in it. And set each control on the form to use the ValidationProvider (using the extended properties on them). You can also set a property (via the SourcePropertyName extented property) name to which the value in the respective control should set to.
    • ValidationProvider class effectively lets you validate values for a given business class’s properties without actually having to have an instance of it at the time of validation.However ValidationProvider is not supported on netcf, due to the unavailability of IExtenderProvider interface.


  • Works with netcf
  • Validation rules can be specified with attributes
  • Business objects can inherit from a provided base class to get the IsValid method (which is used to validate an instance) or use EvilValidator class to do the validation.
  • Don’t have any integration helpers

Fluent Validation

  • Works with netcf
  • Can write validation rules using the builder pattern
    • RuleFor(customer => customer.Postcode).Must(BeAValidPostcode).WithMessage(“Please specify a valid postcode”);
  • Provide MVC framework integration (although as of the time of writing the provided integration is minimal).

NHibernate Validator

  • NHibernate.Validator.dll Works with .netcf
  • Validation rules can be declared using attributes, the builder pattern (ex:- Define(x => x.Name).NotNullableAndNotEmpty();) and XML.
  • Written validators can support applying constrains to the NHibernate meta model. Hence you can use your validation rules to generate an database schema with relevant constrains.
  • “NHibernate Validator is not limited to only be used with NHibernate”.
  • “NHibernate Validator integrates with NHibernate in a native way”
  • Provides integration with
    • WinForms – through NHibernate.Validator.Binding
    • NHibernate
  • Validation is done in a similar way to validation application block.
  • framework can be configured using xml or programaticaly (fluent/builder pattern).

Spring.NET Validation Framework

  • Validation rules can be specified by XML and programmatically.
  • Have WinForms support with Spring.NET RichClient
  • RichClient provides some custom controls, which are not usable in netcf (ie: the custom controls are based on .net controls).

Personally i think the Validation Application Block is the best bet. It has good documentation, features and ‘support’. But i would never know for sure. Got to use it and experience it for my self.

March 19, 2009

Enum.GetValues on .net compact framework

Filed under: Uncategorized — Tags: , , — yasi8h @ 8:25 am

i recently needed to use Enum.GetValues on a .netcf project. but unfortunately it is not there in .netcf. googling gives a lot of solutions that we can use in .netcf. but i couldn’t find one that worked exactly as Enum.GetValue did.

Retrieves an array of the values of the constants in a specified enumeration.

is the method description for the Enum.GetValue, taken from most of the solutions online returned only an array of the constants. not their values. so i came up with the following. now of course this is inspired from lot of smart people’s code that i took from around the net sometime back. 😉

private static string EnumValuesToString(object e)
var eVal = (int) e;
var allValues = GetValues(typeof (Testnum));
var strings = new List();

foreach (var value in allValues)
if (value > eVal)
if ((eVal & value) != value)

return string.Join(“,”, strings.ToArray());

private static int[] GetValues(Type enumType)
if (enumType.BaseType ==
typeof (Enum))
//get the public static fields (members of the enum)
var fi = enumType.GetFields(BindingFlags.Static | BindingFlags.Public);
//create a new enum array
var values = new int[fi.Length];
//populate with the values
for (var iEnum = 0; iEnum < fi.Length; iEnum++) { values[iEnum] = (int) fi[iEnum].GetValue(null); } //return the array return values; } //the type supplied does not derive from enum throw new ArgumentException("enumType parameter is not a System.Enum"); } [/sourcecode] usage would go like [sourcecode language='csharp'] [Flags] public enum Testenum { fld1 = 1, fld2 = 2, fld3 = 4, fld4 = 8, fld5 = 16 } #endregion public ClassTest() { EnumValuesToString(Testenum.fld1 | Testenum.fld2 | Testenum.fld4); } [/sourcecode] may this help me/you/him or her in the future 🙂

November 8, 2008

Some notes about setting the tab order of controls in netcf

Filed under: Uncategorized — Tags: , , — yasi8h @ 3:55 pm

setting the tab order in visual studio is no thing. basically you can set the tab index property using the property grid or you can use the designer to set the tab order. how ever when you have panels in your form(i am talking about a winforms application). setting the tab order becomes a little bit more complicated. for example if we have a form and inside the form we have two text boxes and a panel. and inside this panel we are having another two text boxes. in this case if we want to set the tab order for these controls we have to do it like this. we have to set the tab order for the two text boxes on the form and also for the panel. and then, we have to set the tab order for the two text boxes inside the panel. basically all the controls inside the panel(or any other container control… i guess) have there tab order set separately from the any other controls in any other container. you can see what i mean if you look at the following screen shot. note that this is a .net full framework winfroms application.

image 1

But things are a bit different when it comes to the compact framework. in the netcf if you start a new project and put a form. and basically add all the same controls that we added to the previous project. now when we are going to set the tab index for these controls. you should notice something different. here the panel does not have tab index and tab stop properties(well at least they are not displayed in the designer). so as a result you cannot set the tab order for the panel. this mean you loose the ability to choose the tab order with the same level of flexibility that you had in the full framework.

image 2

but if you look in the panel control. it does have a inherited tab stop property as well as a tab index property. these properties although not displayed in the property grid or though the intellisense inside the visual studio. is still there. and they are been used by the tab order mechanism just as they are used in a full framework application. so basically what this means is you can have the same functionality that you had in full framework winforms app’s tab indexing in netcf apps. but how are you supposed to set the tab index of netcf winfomr’s controls as they are not displaying the properties? well you can set them in your code at the run time.

there might  be several ways to do this. one way would be to create your own panel. and add a custom property to it. for example. we can inherit from Panel and create something like MyPanel. in the which we can create two custom properties called MyTabIndex and MyTabStop.

using System.Windows.Forms;

namespace Winforms.CF.TabIndex.Test
public class MyPanel : Panel
public bool MyTabStop
get { return base.TabStop; }
set { base.TabStop = value; }

public int MyTabIndex
get { return base.TabIndex; }
set { base.TabIndex = value; }

note that when you type in base.TabStop and base.TabIndex the intelisense will not show you these properties. they are ‘hidden’ by default.

now that you have your custom control you can use that instead of the Panel control. this would let you set the tab index(and the tab stop property). which will enable you to set the tab index in all the controls just as you do in any full framework application. i don’t know the reasons for Panel control having these two properties hidden by default in netcf. there might be some reason(s) for this. or else it might be a bug even, who knows 🙂

btw if you try to put ‘new’ properties with the same name as TabIndex and TabStop in your custom control, they will not be visible in the property grid and will not get serialized by the designer. even if you apply some custom attributes like DesignerSerializationVisibility, Broswesable…. it will still not be visible.

using System.Windows.Forms;

namespace Winforms.CF.TabIndex.Test
public class MyPanel : Panel
public new bool TabStop
get { return base.TabStop; }
set { base.TabStop = value; }

public new int TabIndex
get { return base.TabIndex; }
set { base.TabIndex = value; }

this will not get serialized by the designer nor will it be visible through the property grid.

Create a free website or blog at