Tuesday, May 6, 2014

Tip: Workflow Serialization Issue

In Windows Workflow 4.5, serialization of a long running process saves the workflow states (variables' value) and some other information into the database. However it's important to consider carefully the type of objects that the workflow can save. object such as EntitySet and EttityRef of LINQ2SQL by default do not support serialization into database. When try to save such objects into the database, error will be thrown by the workflow runtime:

Operation 'OperationName|IServiceContract' on service instance with identifier '899be275-01f7-45c7-a8d2-ee89595522cb' cannot be performed at this time. Please ensure that the operations are performed in the correct order and that the binding in use provides ordered delivery guarantees.

then

System.Runtime.Serialization.InvalidDataContractException: Type 'System.Data.Linq.EntitySet`1[WhateverObjectType]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute.

See the Microsoft .NET Framework documentation for other supported types. Microsoft does describe some of the thing about LINQ2SQL serialization at Serialization [LINQ to SQL]

We tend to pass in the LINQ2SQL object into the workflow, so one way to workaround the problem is to nullify the object before the WF goes into idle mode. Use the object as a parameter passing vehicle instead of using it to store workflow state.

Tuesday, April 22, 2014

Tip: How to embed different font files for different browser?

Scenario:
Many times you want to embed the necessary font files for the exact browsers that you want to target in order to save internet bandwidth and to improve web site performance. For example, Google Chrome uses the *.svg file to render the best quality of text but other browsers might not support that font file, so you might as well instruct the browser downloads only that font file rather than downloading everyting.

Solution:
Create several css files (i.e.browser specific) that contain the font files declaration. Determine the font file to use at the server or web site host. Here's an example using the ASP.NET MVC:


Friday, April 11, 2014

Tip: Embed open type font (otf) with CSS.

Recently got some font files from the web designer and those files are in otf format. When i tried to embed the font files into CSS i receive the following error from IE10:

         CSS3114: @font-face failed OpenType embedding permission check. Permission must be Installable.

As far i have gathered some information from Google, I need to convert the format to true type (ttf) font. I used the web site http://everythingfonts.com/otf-to-ttf to convert the font files and use the "embed" program from http://carnage-melon.tom7.org/embed/ to change the embed level of the font files so that IE can use them. I used VS2012 to do the code compilation because the original embed.exe does not work on my 64 bit machine.

 Attached here the working program. https://drive.google.com/file/d/0B0QLqsRA_p4pYWhtV2c2Z1FnaWs/edit?usp=sharing

Monday, February 10, 2014

Tip: Controller method attributed with "ClaimsAuthorize" triggers the "ClaimsAuthorizationManager" "CheckAccess" method twice.

If you use the Thinktecture Identity Model framework, most probably you will use the "ClaimsAuthorize" attribute for your methods in a MVC controller class. If you put a break point in your custom authorization manager, you will notice that methods that have the "ClaimsAuthorize" attribute will get called twice. One time for the default Action/Resource and the second for the custom Action/Resource that you have specified in the attribute. The reason for this is that you have registered the "ClaimsAuthorizeAttribute" in the FilterConfig class: and you have instrumented your controller method: The FilterConfig setup is used when we want the WIF framework to trigger the "CheckAccess" for each and every Controller methods in our MVC project. As for the "ClaimsAuthorize" attribute, only methods that are instrumented with it will trigger the "CheckAccess", if the global filter is not set.

Wednesday, October 9, 2013

Tip: IE 10 Issue with MS Report Viewer

Recently I encountered a very strange scenario whereby IE 10 failed to render the Report Viewer properly. All i got was a "disabled" view of the Report Viewer. I tried to switch the browser mode through F12 to "Internet Explorer 10 Compatibility View" with "Standard" document mode. Amazingly the Report Viewer displayed properly and at the same time preserving the CSS3 appearance. I checked the IE debugger console and found that there's a JavaScript error stating "__doPostBack is undefined", so i did a search in Google and found the following link which provides the solution: http://www.hanselman.com/blog/BugAndFixASPNETFailsToDetectIE10CausingDoPostBackIsUndefinedJavaScriptErrorOrMaintainFF5ScrollbarPosition.aspx I tried to download the hotfix from MS web site, but the link was invalid, so i downloaded the nuget browser files from http://www.hanselman.com/blog/BugAndFixASPNETFailsToDetectIE10CausingDoPostBackIsUndefinedJavaScriptErrorOrMaintainFF5ScrollbarPosition.aspx to fix the problem.

Thursday, June 6, 2013

Tip: bat or exe file not running in Windows Task Scheduler (Windows 8)?

Solution:
In order for a task to run successfully using the Windows Task Scheduler, it's important to set the "Start in (Optional)" text box of the task. If you are using the schtasks.exe command to run the task, you can include the "V1" switch so that the mentioned text box is populated automatically. The picture below shows a pre-populated task action using the schtasks.exe.

Monday, June 3, 2013

Tip: How to open a project with Visual Studio in administrator mode?

It's a pain in the ass when have to open a Visual Studio project that is set to run on local IIS and Visual Studio Visual Studio will always complain the lack of permission if the project is opened through double clicking the associated project file in Windows Explorer. The workaround to the problem is to change the windows registry so that every time a Visual Studio associated file is double clicked, it will open the Visual Studio in Administrator context, thus able to modify the IIS metabase. Below is a screen shot of an example which enable VS2010 and VS2012 to run in administrator mode.