Wednesday, October 28, 2009

Clone a generic list


Never thought it would be this easy..

List> insideSpans = replacingDic.Where(d => d.Key.Contains("
List> insideSpansClone = new List>(insideSpans.Count);


insideSpans.ForEach((cloneitem) =>
{
insideSpansClone.Add(new KeyValuePair(cloneitem.Key, cloneitem.Value));
});

Monday, September 07, 2009

Error connecting to undo manager of source file "aspx.designer"

i started getting this error message today after i installed visual studdio team explore 2005

this is how to fix it

1) Right-click the designer file and select delete
2) Right-click the aspx file and select Convert to Web Application

sweet ..

Thursday, August 20, 2009

'content type text/xml; charset=utf-8 was not supported by service ' error

i started getting this error after binding BasicHttpBinding manually. problem is normal WCF calls r using WSHttpBinding. till you change this, it won't solve the problem

System.ServiceModel.WSHttpBinding binding = new WSHttpBinding();

binding.Name = "Test";
binding.CloseTimeout = TimeSpan.Parse("00:01:00");
binding.OpenTimeout = TimeSpan.Parse("00:01:00");
binding.ReceiveTimeout = TimeSpan.Parse("00:10:00");
binding.SendTimeout = TimeSpan.Parse("00:10:00");
binding.BypassProxyOnLocal = false;
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.MaxBufferPoolSize = int.MaxValue;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.MessageEncoding = WSMessageEncoding.Text;
binding.TextEncoding = Encoding.UTF8;
binding.UseDefaultWebProxy = true;
binding.AllowCookies = false;

binding.ReaderQuotas.MaxDepth = int.MaxValue;
binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
binding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
binding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;

return new TranscriptServiceClient(binding, new EndpointAddress(new Uri("http://localhost:10780/TranscriptService.svc")));

Monday, July 27, 2009

Repeater Control scroll to top on post back

There is an issue in the repeater control reset on a post back.

here is my solution ..



// Hidden field to store the last scrolled posistion























// Make sure we register our script is excuted when scrolling event is fired on wrapped DIV

protected void Page_Init(object sender, EventArgs e)
{
this.divChatRepeaterContent.Attributes.Add("onscroll", "javascript:storeScrollValue(this)");
}

Friday, July 24, 2009

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state

this error also could come if you have specified the URL to connectiont to the WCF is incorrect .. just figured it out ..!

endpoint address="http://localhost:10780/TranscriptService.svc"

for more details, you need to inspect the InnerException of the exception!

Thursday, July 23, 2009

Security negotiation failed because the remote party did not send back a reply in a timely manner.

Security negotiation failed because the remote party did not send back a reply in a timely manner. This may be because the underlying transport connection was aborted.

very often you might get this error if you have a ASP.NET + WCF project ..

means you need to clean and rebuild the project .. ;)

if didn't work .. delete the WCF reference and re-add . works like a charm

or if u have specified aspNetCompatibilityEnabled="true" . remove it and try. this happend if you have enable WCF + Javasctipt enabled

Security negotiation failed because the remote party did not send back a reply in a timely manner.

Security negotiation failed because the remote party did not send back a reply in a timely manner. This may be because the underlying transport connection was aborted.

very often you might get this error if you have a ASP.NET + WCF project ..

means you need to clean and rebuild the project .. ;)

Wednesday, July 22, 2009

ASP CSS Friendly Control Menu Bug

ASP CSS Friendly Control Menu Bug has a bug when you click on one menu item it's not firing MenuItemClick event ..

after hours of work found the soulution.

Replace the MenuAdapter.cs BuildItem() function with this

private void BuildItem(MenuItem item, HtmlTextWriter writer)
{
Menu menu = Control as Menu;
if ((menu != null) && (item != null) && (writer != null))
{
writer.WriteLine();
writer.WriteBeginTag("li");
writer.WriteAttribute("class", item.ChildItems.Count > 0 ? "AspNet-Menu-WithChildren" : "AspNet-Menu-Leaf");
writer.Write(HtmlTextWriter.TagRightChar);
writer.Indent++;
writer.WriteLine();

if (item.NavigateUrl.Length > 0)
{
writer.WriteBeginTag("a");
writer.WriteAttribute("href", Page.ResolveUrl(item.NavigateUrl));
writer.WriteAttribute("class", "AspNet-Menu-Link");
if (item.Target.Length > 0)
{
writer.WriteAttribute("target", item.Target);
}
if (item.ToolTip.Length > 0)
{
writer.WriteAttribute("title", item.ToolTip);
}
else if (menu.ToolTip.Length > 0)
{
writer.WriteAttribute("title", menu.ToolTip);
}
writer.Write(HtmlTextWriter.TagRightChar);
writer.Indent++;
writer.WriteLine();
}
else
{
// Modified here... add a self refering link back to the menu

writer.WriteBeginTag("a");
writer.WriteAttribute("href", Page.ClientScript.GetPostBackClientHyperlink(menu, "b" + item.ValuePath.Replace(menu.PathSeparator.ToString(), "\\"), true));

writer.WriteAttribute("class", "AspNet-Menu-Link");
if (item.Target.Length > 0)
{
writer.WriteAttribute("target", item.Target);
}
if (item.ToolTip.Length > 0)
{
writer.WriteAttribute("title", item.ToolTip);
}
else if (menu.ToolTip.Length > 0)
{
writer.WriteAttribute("title", menu.ToolTip);
}
writer.Write(HtmlTextWriter.TagRightChar);
writer.Indent++;
writer.WriteLine();

}

if (item.ImageUrl.Length > 0)
{
writer.WriteBeginTag("img");
writer.WriteAttribute("src", Page.ResolveUrl(item.ImageUrl));
writer.WriteAttribute("alt", item.ToolTip.Length > 0 ? item.ToolTip : (menu.ToolTip.Length > 0 ? menu.ToolTip : item.Text));
writer.Write(HtmlTextWriter.SelfClosingTagEnd);
}

writer.Write(item.Text);

if (item.NavigateUrl.Length > 0)
{
writer.Indent--;
writer.WriteLine();
writer.WriteEndTag("a");
}
else
{
writer.Indent--;
writer.WriteLine();
writer.WriteEndTag("a");
//writer.WriteEndTag("span");
}

if ((item.ChildItems != null) && (item.ChildItems.Count > 0))
{
BuildItems(item.ChildItems, false, writer);
}

writer.Indent--;
writer.WriteLine();
writer.WriteEndTag("li");
}
}

Tuesday, June 23, 2009

Get property value without casting to it's original source

Today I had a requirement to check a property value without casting or converting it back to it's source class.

this is one way i foundout doing it..


Type t = element.DataContext.GetType();

foreach (var prop in t.GetProperties())
{
if (prop.Name == "MessageType")
{
string messageType = prop.GetValue(element.DataContext, null).ToString();
break;
}
}

Monday, June 22, 2009

Silverlight Developer Toolbar

last couple of days i was looking for an application same like IE Developer toolbar to check style issue on IE brower and i found this awsome free tool


http://silverlightspy.com/

Thursday, May 28, 2009

Panel Hit Test in C# winforms

Today i wanted to check whether user click in with in the context of the panel. Since panel doesnt provide hittest this is how to do it ..

private bool panel_hit_test(Panel panel, POINT point_test)
{

Rectangle rect = panel.RectangleToScreen(panel.ClientRectangle);


if ((point_test.x > rect.X && point_test.x < rect.X + rect.Width) &&
(point_test.y > rect.Y && point_test.y < rect.Y + rect.Height))
{
return true;
}
else
return false;
}

Tuesday, May 05, 2009

Light-weight Threading ..

Today i wanted to create a light weight UI thread to make a button bliking. here is the sample code.

ThreadPool.QueueUserWorkItem(BlinkChatButton);


private void BlinkChatButton(object state)
{

while (canBlink)
{

Thread.Sleep(1000);
}


}

Windows Media (WM) Screen capturing by window handle

There is a C++ interface MS has provided to do this but in .net C# interop it's not available.

You have to use the IPropertyBag class based on it's GUID

[Guid("55272A00-42CB-11CE-8135-00AA004BB851")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IPropertyBag
{
void Read(String propName, out object ptrVar, int errorLog);
void Write(string propName, ref object ptrVar);
}



and copy and past this code before starting

IPropertyBag ipb = (IPropertyBag)
object value = false;

ipb.Write("Screen", ref value);
ipb.Write("CaptureWindow", ref Int32OfHandler);


Also make sure when you set the handle to set the encoding also to screen capturing


object codecName;
int codec_index = 2;

for (int i = 0; i < Profile.VideoCodecCount; ++i)
{
lVid4cc = Profile.EnumVideoCodec(i, out codecName);

//Compare if the current codec is Windows Media Video 9 Screen
if (codecName.ToString().Equals("Windows Media Video 9 Screen"))
{
codec_index = i; exit for;
}
}

// Set the IWMEncAudienceObj
Audnc.set_VideoCodec(0, codec_index);

Friday, March 13, 2009

how to get the size of a byte array in C#

System.IO.MemoryStream stream = new System.IO.MemoryStream();

System.Runtime.Serialization.Formatters.Binary.BinaryFormatter objFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
objFormatter.Serialize(stream, byData);
long size = stream.Length;

Friday, March 06, 2009

The remote server returned an error: NotFound WCF

This is a very common error message. To solve this, first you need to enable loggin in WCF. (Search for WCF Logging on Google) . Make you in logging section you enable all the types of the error messages

Eg


logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="false"
maxSizeOfMessageToLog="2147483647" />


then you can see the exception on the error log file..


I got this error message because i have not set max request length, you need to add this to the web.config file

Wednesday, March 04, 2009

400 - Bad Request response

I was getting this message on the newly created silverlight app and it was driving me crazy.

this is how to fix it

in the ServiceReferences.ClientConfig


and in the Web Site project. Web.config file




maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">






bindingConfiguration="MyBinding" contract="TranscriptViewerWebApp.IRFTranscriptService">

















Monday, February 02, 2009

Custom tool error: Failed to generate code for the service reference 'ServiceReference1'. Please check other error and warning messages for details.

Custom tool error: Failed to generate code for the service reference ''. Please check other error and warning messages for details.

this is another issue i was stuck for sometime.. reason was i created the silverlight project using the Blend 2 with SP1 and created the WCF project using the VS2008 SP1.

to solve this problem you have to create silverlight application also using VS2008

Error 11007: Entity type '' is not mapped.

Most of the time u will get this bug or the table will not get added to the model (.edmx file) if you don't have a Primary Key in the database table ! so watch out !

Tuesday, January 27, 2009

The remote server returned an error: NotFound

The remote server returned an error: NotFound exception is a bich. !!

this is a very common issue in SilverLight beta 2,

to solve this,

1. you have to enable includeExceptionDetailInFaults to true










2. Download firebug, and inspect the issue, or the error code.

3. Search the error code in google ;)

4. if it's "415 - Unsupported media type" then only thing u have to do it change the

binding="wsHttpBinding" to binding="basicHttpBinding" in .conig file ..

DISCO it works!!!