Thursday 16 December 2010

HTML ruler

Source from http://reeddesign.co.uk/test/points-pixels.html


http://www.soft.tahionic.com/download-ruler/index.html



ReedDesign

Approximate Conversion from Points to Pixels

(and Ems and %)

Here's a chart that converts points to pixels (and ems and %). It's an approximation, which will depend on font, browser and OS, but it's a good starting point.
Points Pixels Ems Percent
6pt 8px 0.5em 50%
7pt 9px 0.55em 55%
7.5pt 10px 0.625em 62.5%
8pt 11px 0.7em 70%
9pt 12px 0.75em 75%
10pt 13px 0.8em 80%
10.5pt 14px 0.875em 87.5%
11pt 15px 0.95em 95%
12pt 16px 1em 100%
13pt 17px 1.05em 105%
13.5pt 18px 1.125em 112.5%
14pt 19px 1.2em 120%
14.5pt 20px 1.25em 125%
15pt 21px 1.3em 130%
16pt 22px 1.4em 140%
17pt 23px 1.45em 145%
18pt 24px 1.5em 150%
20pt 26px 1.6em 160%
22pt 29px 1.8em 180%
24pt 32px 2em 200%
26pt 35px 2.2em 220%
27pt 36px 2.25em 225%
28pt 37px 2.3em 230%
29pt 38px 2.35em 235%
30pt 40px 2.45em 245%
32pt 42px 2.55em 255%
34pt 45px 2.75em 275%
36pt 48px 3em 300%

Monday 22 November 2010

Could not load file or assembly 'Name' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I have seen these a few times lately and the cause is usually that you have the following configuration:
  • IIS running on a 64Bit Operating System
  • The Assembly DLL in question has been compiled for 32Bit - check the project properties under the build tab, if under platform target you have x86 then it is 32bit only.

    x86 
Why would you have a 32bit only DLL? well it could be that you are using something that is not 64bit compatible, such as MAPI or ODBC...
The real problem is that the 64Bit IIS machine is using an Application Pool that is not allowing a 32bit DLL to be processed.
Open IIS Manager and find the application pool for the site and select the Advanced Settings.
AppPoolAdvSettings

Notice that there is an option called "Enable 32-Bit Applications" this is the cause of the error. Enable this and you should be good to go.
Here is an example of the full error for this message.

Server Error in '/' Application.


Could not load file or assembly 'XMLView' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.BadImageFormatException: Could not load file or assembly 'XMLView' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Assembly Load Trace: The following information can be helpful to determine why the assembly 'XMLView' could not be loaded.

=== Pre-bind state information === LOG: User = NT AUTHORITY\NETWORK SERVICE LOG: DisplayName = XMLView (Partial) LOG: Appbase = file:///C:/dev/Projects/OSCARUtils/ LOG: Initial PrivatePath = C:\dev\Projects\OSCARUtils\bin Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\dev\Projects\OSCARUtils\web.config LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/root/8a8c3f22/9d24bab0/XMLView.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/Temporary ASP.NET Files/root/8a8c3f22/9d24bab0/XMLView/XMLView.DLL. LOG: Attempting download of new URL file:///C:/dev/Projects/OSCARUtils/bin/XMLView.DLL. ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
Stack Trace:

[BadImageFormatException: Could not load file or assembly 'XMLView' or one of its dependencies. An attempt was made to load a program with an incorrect format.] System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0 System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +465 System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +181 System.Reflection.Assembly.Load(String assemblyString) +42 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +190 [ConfigurationErrorsException: Could not load file or assembly 'XMLView' or one of its dependencies. An attempt was made to load a program with an incorrect format.] System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +3637752 System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +397 System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +155 System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +36 System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +235 System.Web.Compilation.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +214 System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +57 System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +259 System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +406 System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +125 System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +203 System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +52 System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +50 System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +410 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +274

Version Information: Microsoft .NET Framework Version:2.0.50727.1378; ASP.NET Version:2.0.50727.1378
posted on Monday, November 05, 2007 2:49 PM |

Wednesday 27 October 2010

How to Make LINQ to SQL Check for Changes After Attach (or AttachAll)

dbContext.Entity.Attach(entity, true);
//submit insert or update to db
dbContext.SubmitChanges();

Problem: entity was saved, but its dependencies weren't.

Solution 1: Try to loop its dependencies and attach manually
    foreach (var child in entity.children)
   {
          dbContext.Child.Attach(child);
   
          get error at this line: An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.
   }

- Solution 1 is completely wrong to resolve the problem
Root cause of Problem: LINQ to SQL assumes that the object you are attaching is un-modified. True, there is an overloaded method "AttachAll(items, true)" that forces LINQ to view those objects as 'modified', but that method only works if your table has a TimeStamp field.

How to resolve: So, how do I tell LINQ to SQL to see if there have been changes made to already-existing entities? By using the "Refresh" method:
// Add this line before "SubmitChanges"
dataContext.Refresh(RefreshMode.KeepCurrentValues, entity);

Completed code as following
.Entity.Attach(entity, true);
dbContext.Child.InsertAllOnSubmit(entity.Children.Where(r => r.Id == 0));

dbContext.Refresh(RefreshMode.KeepCurrentValues, entity);
dbContext.Refresh(RefreshMode.KeepCurrentValues, entity.Children.Where(r => r.Id != 0));


//submit insert or update to db
dbContext.SubmitChanges();

Sunday 10 October 2010

ASP.NET MVC

============ LESSON LEARN ========
Model: consist of business logic, data access logic
View: Markup and content that is returned to the browser
Controller: Fires off some logic and response to a browser request

MAPPING URL ROUTING
Global.asax.cs: Using <routes> table to map url and its parameters

MUST DO
1. Follow MVC framework naming convention

============ RESOURCE ===========
1. Download ASP.NET MVC 2 framework
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c9ba1fe1-3ba8-439a-9e21-def90a8615a9&displaylang=en

2. Understanding overview of ASP.NET MVC
http://www.asp.net/mvc/videos/understanding-models-views-and-controllers

3.Five Must Have Tools for MVC Developers
http://www.codecapers.com/post/Five-Must-Have-Tools-for-MVC-Developers.aspx

Visual Studio 2008 (Some shorcut keys)

Here are some extremely helpful keyboard shortcut keys for Visual Studio 2008. You probably know most, but some you won't know. For instance, did you know that Ctrl+. is the same as Sift+Alt+F10?
Note: Some of the shortcuts won't work in all environment configurations (web, C#, etc).
To use, hold down the control key and hit the key combination. Works on the whole document, a specific line, or a selection of code.
Go to Definition (F12) Navigate to the definition of the method or variable. Super useful.
Find all References (Shift + F12)
Update References/ Add Using Statement (Ctrl +. or Shift +Alt +F10) I'm referring to the underline that appears under a variable to perform an action like add a using statement, or refacter a method or class name. Not sure what it's called but I use it all the time. Ex: ClassName
List Members (Ctrl +J or Ctrl +K, L) Displays the autocomplete list for classes, methods, or properties.
List Parameter Info (Ctrl +Shift +Space or Ctrl +K +P) Lists the parameters for a method. Use this shortcut when your cursor is inside the parenthesis of a method.
Auto Format (Ctrl +K, D or Ctrl +E, D) Formats C#, VB, ASPX, Javascript, CSS, XML, XSL, and HTML code according to generally accepted formatting standards for the respective programming language. Makes code look nice and neat.
Quick Watch (Ctrl +Alt +Q) Highlight some code and hit these shortcut keys to display the Quick Watch dialog.
Comment / Uncomment (Ctrl +K, C / Ctrl +K, U) Comments or uncomments a block of code. Works with C#, VB, ASPX.
Code Bookmarks Use these to bookmark a line of code. You can cycle through the bookmarks across any file within a project. Bookmarks come in very handy, try it out.
Set/Unset Bookmark (Ctrl +K, K) Next Bookmark (Ctrl +K, N)
Surround With (Ctrl +S) Surrounds a block of code with a code snippet.
Build & Debug Shortcuts Set/Unset Breakpoint (F9) Build (F6 or Ctrl +Shift +B) Start Debugging (F5) Start Without Debugging (Ctrl +F5) Stop Debugging (Shift +F5) Continue (F5) Step Over (F10) Step Into (F11) Step Out (Shift +F11) Attach to Process (Ctrl + Alt + P)
That's it for now, feel free to add more in the comments below. I'll try to update this post periodically.

Copy from Rob Volk's Dev Blog
http://blog.robvolk.com/2009/01/visual-studio-2008-keyboard-shortcuts.html