Categories
.NET C#.NET VB.NET/VB WPF

Self Hosted Web Service: WebServiceHost

So today I learn about WebServiceHost. Just a normal class but it does a lot for me today. This host the web service within you Desktop/Windows Service application. i.e. you don’t need to install any Web server or other stuff, just create a Service Contract Class and use WebServiceHost to host it within your application.¬†

I need this as part of my project, because I have to pass some server information to my application. I initially create a Seperete web application for this, but why maintain another application and increase setup time when I can host it within. I need it for just one particular value to be pass in JSON format to my client side. However one thing I must tell here is that the Host server application must be running as Administrative¬†privilege or the service won’t start. For Windows Service run application as “LocalSystem” rather than default LocalService to keep it working.

It solve lot of problem and architectural issue I had in my project.  

Categories
.NET C#.NET VB.NET/VB WPF

WPF ComboBox: DataBinding with DataTable

Well it seems easy thing, but it took a while for me to get it working. Frankly I still don’t know why it works this way, but at least it works. With WPF I was expecting something as easy as giving DataTable object to ComboBox by it’s property and define the Data Field and Value field as in ASP.NET dropdownlist and it will bind, but this was not the case or at least the syntax is little different. So it goes like

ComboBox cb = new ComboBox(); /// You might already have object of it, so I just create it for sake of understanding here.
cb.ItemSource = MyDataTable.Rows; /// Yup, DataTable will not bind but it's rows collection will.
cb.DisplayMemberPath = ".[" + YourColumnNameVariable + "]"; ///in other other ".[columnname]" is what is expected;
cb.SelectedValuePath = ".[" + YourColumnNameVariable2 + "]"; ///in other other ".[columnname]" is what is expected;

This is all we need to do to get it working.

Categories
.NET ASP.NET C#.NET VB.NET/VB WPF

GDI+ Generic Error

I see lot of people asking about GDI+ Generic Error. Since this is “generic” error nobody can tell what is wrong with code. So did a work around and get it working. I had this error quite a time in early days of my programming and just found same error in one of junior’s code. Well from my experience I can say one thing. GDI+ Generic error 99.9% means “developer miss a detail or overlooked something”. Most common reason of error are negligence of

1. Path should be physical path

2. All folder should present before you create file.

3. Previous files should be in write mode if case of overriding files.

4. Make sure permission are for writing to User of process.

5. Do not include any special character which windows do not permit in folder name or file name.

6. FILE FORMAT has nothing to do with this error most often.

7. Recheck permission if you try all above.

8. Recheck Path again :).

Point #7 and #8 are most important solution and always works for me.