mayvelous

Me, Myself and Mayvelous

Archive for the ‘C#’ Category

I have this project setup for continuous integration with cruise control. It’s been up and running for quite sometime then suddenly the website starts getting the following errors on every successful build.

Exception Details: System.BadImageFormatException: Could not load file or assembly ‘Microsoft.VisualBasic.Activities.Compiler’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

The Error Page
Solution/Project Platform Target Configuration + Cruise Build

I did not make any changes to the build configs at all and the site runs fine locally. There is no reference to ‘Microsoft.VisualBasic.Activities.Compiler‘ in my project and it doesn’t have VB code. I found some extra files, see below list, in the deployment bin while comparing the bin assemblies on deployment server and my local. Once remove those files, the site comes back on, but the files are added with every cruise build.

  • Microsoft.VisualBasic.Activities.Compiler.dll
  • Microsoft.Practices.ServiceLocation.dll
  • Microsoft.Practices.ServiceLocation.xml
  • mscorlib.dll
  • normidna.nlp
  • normnfc.nlp
  • normnfd.nlp
  • normnfkc.nlp
  • normnfkd.nlp
  • PresentationCore.dll
  • System.Data.dll
  • System.Data.OracleClient.dll
  • System.EnterpriseServices.dll
  • System.EnterpriseServices.Wrapper.dll
  • System.Printing.dll
  • System.Transactions.dll

I google a bit to check similar problems out there and found only one link, which was fixed by installing missing SDK or something. I didn’t think that was the right solution for me but got an idea to check for target platform configuration on the solution and project files.

I compare with one of my working project many times using visual studio property window to check for the solution and project file configuration properties but they seemed to be the same, using ANYCPU for the build platform. I didn’t trust the VS property designer so used WinMerge to compare the two files and found that there are some additional configuration lines added to the solution file. So I open the .sln and .csproj in notepad, removed all the extra configs, see the image below, checked back in, forced build the Cruise Control and walah all those craps gone and the site is back to the way it was.

.sln Solution file comparison and the lines to remove
Solution/Project Platform Target Configuration + Cruise Build

.csproj Project file comparison and the line to remove
Solution/Project Platform Target Configuration + Cruise Build

The point I like to make here is that although no error with cruise build, your site can still be broken and freaking Visual Studio design views lie many time so remember to go for the good old way of editing it in notepad.

Note: If you don’t have any working version to compare, just search for “Mixed Platforms” or “x86” in .sln file and “<PlatformTarget>AnyCPU</PlatformTarget>” in .csproj file and remove them accordingly.

I learn something new today (I’m sure most of you already know, but I just found out). I didn’t know we can use html tags such as div, span etc as html server controls. I do know if you want to convert html controls into server control, you just have to add runat=”server” element but using div container as server control is a different story.

I normally use literal or panel server controls to show or hide the confirmation messages. But in this code, the div tag can act as a panel control by declaring it as HtmlGenericControl.

In the front-end you add id and runat=”server” elements to the div tag.

<fieldset>
	<h3>Registration Validation</h3>
	<div id="divValidated" runat="server">
		Your account has been validated. You may now log in.
	</div>
	<div id="divNoAccount" runat="server">
		No matching account. If it has been over 30 days since you registered your
		account will have been deleted. Please sign up again.
	</div>
	<div id="divNoNeed" runat="server">
		Your account has already been validated.
	</div>
</fieldset>

In the back-end you declare it as HtmlGenericControl.

protected System.Web.UI.HtmlControls.HtmlGenericControl divValidated;
protected System.Web.UI.HtmlControls.HtmlGenericControl divNoAccount;
protected System.Web.UI.HtmlControls.HtmlGenericControl divNoNeed;

Voila, you got your div panel with all those member variables you can make use of. So here is a little info on HtmlGenericControl.

Use this class to represent an HTML server control element not directly represented by a .NET Framework class, such as <span>, <div>, <body>, or <font>.
Caution
This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. ASP.NET provides an input request validation feature to block script and HTML in user input. Validation server controls are also provided to assess user input.
HtmlGenericControl Class
HtmlGenericControl Members

Pretty cool isn’t it? Well, I didn’t know that and now I know. :D

C# Yellow Book

Yellow Book - Rob MilesI came across this “C# Yellow Book” by Rob Miles, MVP and a lecturer in the Department of Computer Science at University of Hull, and thought of sharing.

I think this would be good introductory reading for those of us learning C#

The C# Book is used by the Department of Computer Science in the University of Hull as the basis of the First Year programming course.

Download: Rob Miles CSharp Yellow Book 2008.pdf(1.4M)

I rolled his blog also; he posts pop quizzes every now and then.

  • Comments Off
  • Filed under: C#, Development, Downloads, eBooks, General, Technology
  • Filtering Date Parts in LLBLGen

    Keeping in mind that LLBLGen generate dynamic sql statements and no need for storeprocedures, sometimes it’s hard for me to find the right code to retrieve data using complicated queries. Eg. those of multiple JOIN statements and DATEPART functions.

    The followings can be used in search functions where you search by date range or by datepart such as by Day or Month or Year.

    For my first scenario, I want to search records by “Date” ie. “dd/MM/yyyy” only and not considering the Time part.

    By default when you insert a Date using WinForm DateTimePicker or Infragistic ultraDatePicker, the Time part goes in as 0s. eg. “10/01/2008 12:00:00″. But sometimes there are cases where you have to record the Time as well. My saved records include default Date values as well as DateTime values.

    (more…)

  • 4 Comments
  • Filed under: .Net, C#, Development, Work
  • LLBLGen vs CodeSmith

    Comparison between LLBLGen Pro and CodeSmith tools. I’m very new to both so the following points might be completely wrong. So correct me please and do fill in more.

    LLBLGen CodeSmith
    O/R Mapper + Code Generator Template based Code Generator
    Uses Parameterized Dynamic Queries Mainly Stored procedures
    Cost license fee,
    Need to buy template studio for custom template creation/management.
    Free (console version)
    Comes as templates so add/update or manage as you wish.
    On-fly code generation, you don’t get to see templates or whatsoever. Gives control over the whole process, top-bottom, as they are managed by individual templates
    Does not create DB schema/generation. Creates the whole DB structure ie. Storeprocs, triggers, tables, functions etc
    N-tier generated with one go ie. If you change something in DB, you just regenerate the llblgen project and all files get updated. Individual template/batch file generation ie. You need to run B&D batch, channel batch etc one by one to get update files across 3 layer solutions.
    No webservices, remoting or channel server. Just uses classes and collections – entities, typelist, typeviews etc Can add as much layer separation between DB end and UI end. Can manage as you wish just by working on templates
    Less code – 2 projects, 1 solution More code, some redundant – multiple projects, 3 solutions
    N-tier project structure
    - Database Generic
    - Database Specific
    - UI
    (2 types: Adapter based or SelfServicing)
    N-tier project structure
    - Business and Data
    - Public Channels
    - Presentations
    (Add more as you wish)
    Do sorting, filtering, grouping, paging, all DB queries by a few class calls. (Dynamic queries) Need individual storeproc for each function. Adding one function needs to do individual updates for all projects and across solutions as well. Extensive use of storeproc.
    It is n-tier but basic multi tier structure which separate Business data code from UI codes. Advance/better n-tier architecture. Greater security and more control over each layers.
    Easier code generation + usage + less error generation. Need proper setup or you’ll get tangle in between. Small error in your base template will affect the entire project code.
    You write very little code ie. Only need to write for UI code. You have to write all the codes for your based templates if you don’t already have templates in hand.
    Provide .net 1.1, and .net 2.0 classes, ready to use and choose whichever you need. No .net 2.0 codesmith templates for us yet. Can use third-party templates but it will cost us.
    It doesn’t require dotnet framework and work independently. Uses dotnet framework as main backbone.

    # References:

    # Debate: O/R Mapping or Code Generation : Lots of discussion going on there in the reply threads.
    # Your Favorite O/R Mapper? : A discussion on O/R Mappers
    # CodeSmith Rocks! | When code generation goes bad…
    # LLBLGenPro vs CodeSmith w/ .netTiers

    Study Notes

    I’m learning new things these days and am just sharing some notes here. I’m still learning and these technologies are very new for me, hence my notes gonna have heaps of errors and wrong information. You are most welcome to correct them, fill some more in and share you notes with me too. Alright, so we are set to go.

    I’ll be updating this post with links so still tune.

    All the notes are subject to change as I’ll be filling in with more info later.

    Flickr Photos

    Downloads

    Twitter Status


    Goodie Links


    Mayvelous Friends


    I'm an Author for Global Voices

    Archives