Thursday 23 June 2011

Could not load file or assembly XX. System.BadImageFormatException

I got this error when I was working with Silverlight RIA application which works on MVVM pattern. Everything was running smoothly before when I was using VSTS2010 internal web server. As soon as I host my asp.net application which host silverlight application to IIS 7 of windows 7 I got the above error.

Although I was using dll which was built on any CPU platform. After some digging I found out that there is a setting in IIS 7 in Application Pool that you can set.
Open IIS using InetMgr command, locate & click your web application. In the action tab select Advanced Settings and view your application pool.
Now goto application pool and locate the pool viewed in last step. Click your pool and select Advanced Settings from action tab. In General settings Enable 32-Bit Applications set this value to true.
After setting this when I tried to run the application, I got "Login failed for user 'IIS APPPOOL\ASP.NET v4.0'" error. You may overcome this by going to Process Model in Application pool and in Identity setting, change ApplicationPoolIdentity to NetworkService or LocalSystem and you're go.

Make sure to remove anonymous access and add windows authentication (if using windows auth) to your asp.net web application.

Thursday 19 May 2011

Windows App : Set an image in ListViewSubItem

For background details about the error, see this link...
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/229d8b6e-f167-48ee-aa2e-931e6ee7eb2b/


If you really do wanna set an image in ListVewSubItem, it's a bit tricky. You've to handle the following events of a list view
DrawSubItem
DrawColumnHeader


Now implement DrawColumnHeader

private void ListViewDrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            e.DrawDefault = true;
        }

And DrawSubItem
private void ListViewDrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
       if (e.ColumnIndex == 1)
       {
          ((TriboldExtendedListView) sender).FullRowSelect = true;

if (e.ColumnIndex == 1)
{
//This allows window to draw background otherwise your column would be blank in //anyway
e.DrawBackground();

//Draw you graphics here
e.Graphics.DrawImage(img, new System.Drawing.RectangleF(e.Item.Position.X + Columns[0].Width - 10, e.Item.Position.Y, img.Width*(fScale), img.Height*(fScale)));

//Draw your text here
e.DrawText(TextFormatFlags.Left);



//This is something really important if you want to set the highlighted color //(windows blue) to the ListViewSubItem
e.Item.UseItemStyleForSubItems = false;
if (e.Item.Selected)
{

 e.Item.SubItems[1].BackColor = System.Drawing.Color.FromArgb(51, 153, 255);
 e.Item.SubItems[1].ForeColor = System.Drawing.Color.FromArgb(255, 255, 255);
}
else
{
 e.Item.SubItems[1].BackColor = System.Drawing.Color.FromArgb(229, 229, 229);
 e.Item.SubItems[1].ForeColor = System.Drawing.Color.FromArgb(0, 0, 0);
}

}}
}

If you need any information about, feel free to post.

Tuesday 22 March 2011

WCF service giving socket connection time-out error

After spending about 3 hrs on this I came to know that I was doing a silly mistake. Here is the full scenerio...


I've created a class named ChangeSet inheriting from the interface IChangeSet. I wrapped up the result in a wrapper called GetAllLaunchEntitysResponse and returning from the proxy class as follows:


        public GetAllLaunchEntitysResponse GetAllChangeSetList()
        {
            using (var factory = new TriboldChannelFactory<IChangeSetService>("IChangeSetService"))
            {
                return factory.CreateChannel().GetAllChangeSet();
            }
        }


Also, before doing that, I've already created a WCF service and proxy to call the service endpoint. The function GetAllChangeSet() returns a list of change set interface (List<IChangeSet>) wrapped in GetAllLaunchEntitysResponse object from the DAL. 


I was getting the following error from the WCF service when calling from a proxy service.


The socket connection was aborted. This could be caused by an error
processing your message or a receive timeout being exceeded by the remote
host, or an underlying network resource issue. Local socket timeout was
'00:01:00'.

First thing that came in my mind is to check the configuration files. The endpoint was already set in the config file for both client & server as well. The timeout setting was set for 5 minutes...so that was not the case of time-out but something else which was triggering this error to raise.


Then I start thinking if there might exists any complex data-types present in ChangeSet class causing problem in serialization. So I commented complex data types and keep Int & string data-types only and call the service. Result was the same as before.


Then I change the return type from List<IChangeSet> to IChangeSet thinking there might be some problem returning list from WCF service. I call  the service & again result was same as before.


Now the last thing I tried was to replace the class name instead of interface from the list. i.e. List<IChangeSet> replaced by <List<ChangeSet> and call the WCF service again.


HURRAH....This time it worked....The silly mistake I was doing was returning a list of interfaces of ChangeSet (List<IChangeSet>) which cannot be seriablized since only class, struct and enum can be serialized and not interface [the fundamental concept of WCF service]


I am writing this post for someone who is doing the same mistake as I did. Be sure to serialize only class object and not Interface.

Test Blog

This is test blog