Winforms UI Best practices: Form.AutoValidate = EnableAllowFocusChange

Set on every form: Form.AutoValidate = EnableAllowFocusChange

 

image
image Figure: Form.AutoValidate = EnablePreventFocusChange, prevents you from leaving your textbox until your data entry is correct

 

image
image Figure: Form.AutoValidate = EnableAllowFocusChange with Errorproviders tell you bad data entry, but let you change to other controls

Microsoft CRM 4: CrmException: Expired Key

Since Google gave me only 1 solution in Russian for this, I post here my solution

If you encounter the following exception in Microsoft CRM

Error Description:

The key specified to compute a hash value is expired, only active keys are valid. Expired Key :
CrmKey(Id:a3ed4202-4ebb-dd11-b530-00155d012118, ScaleGroupId:00000000-0000-0000-0000-000000000000, KeyType:CrmWRPCTokenKey,
Expired:True, ValidOn:11/26/2008 00:06:02, ExpiresOn:12/29/2008 00:06:02, CreatedOn:11/26/2008 00:06:02, CreatedBy:NT AUTHORITY\SYSTEM.

Error Details:

The key specified to compute a hash value is expired, only active keys are valid. Expired Key :
CrmKey(Id:a3ed4202-4ebb-dd11-b530-00155d012118, ScaleGroupId:00000000-0000-0000-0000-000000000000,
KeyType:CrmWRPCTokenKey, Expired:True, ValidOn:11/26/2008 00:06:02, ExpiresOn:12/29/2008 00:06:02,
CreatedOn:11/26/2008 00:06:02, CreatedBy:NT AUTHORITY\SYSTEM.

Full Stack:

[CrmException: The key specified to compute a hash value is expired, only active keys are valid.
Expired Key : CrmKey(Id:a3ed4202-4ebb-dd11-b530-00155d012118, ScaleGroupId:00000000-0000-0000-0000-000000000000, KeyType:CrmWRPCTokenKey, Expired:True,
ValidOn:11/26/2008 00:06:02, ExpiresOn:12/29/2008 00:06:02, CreatedOn:11/26/2008 00:06:02, CreatedBy:NT AUTHORITY\SYSTEM.] at Microsoft.Crm.CrmKeyService.ComputeHash(CrmKey key, Guid scaleGroupId, HashParameterBase[] parameters) at Microsoft.Crm.CrmKeyService.ComputeHash(CrmKey key, HashParameterBase[] parameters) at Microsoft.Crm.Application.Security.WRPCContext..ctor() at Microsoft.Crm.Application.Controls.AppPage.ValidateWrpcContext() at Microsoft.Crm.Application.Controls.AppPage.OnInit(EventArgs e) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) [HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown.] at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.default_aspx.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Other Message:

Error Number: 0x8004A106

Source File: Not available

Line Number: Not available

 

Make sure "Microsoft CRM Asynchronous Processing Service" is running.

image

Entity Framework: How to set Defaultvalues for DateTime fields

It's easy I thought, just select the Property of the EntityType and set the Default Value in the Properties window to: DateTime.Now
image

But it's not

Defaultvalues get validated on Compile time not on Design time.
So after Rebuild you get:

Error      1              
Error 54: 
Default value (System.DateTime.Now) is not valid for DateTime. The value must be in the form 'yyyy-MM-dd HH:mm:ss.fffZ'.                
C:\DataPeterGfader\ProjectsTFS\ImportantClient\Business\Entities\MyImportantModel.edmx 

How to set then the default value?

Use the constructor of the Entity.
Yes I know that it's not nice to to this manually!

Example code

    public partial class Transactions
    {
        public Transactions()
        {
            //HACK: To prevent this error: {"SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."}
            this.LastModified = System.DateTime.Now;
        }
    }

Note to myself: TFS checks-in only changed and checkedout items

Nothing checked out
image

Open form in Designer
image

Visual Studio checks out all 3 files

  • FormStartup.resx
  • FormStartup.cs
  • FormStartup.Designer.cs

On Checkin
image

 

Shock: I only changed a text on a label. Why are all 3 files checked out.

 

But then in --> View History --> Changesets there is only 1 file

image

 

Remember to right click on Designer.cs file (contextmenu), else you get the wrong history!!

Latest Posts

Popular Posts