Thursday, May 27, 2010

Not a nullale type - C# 2008

Complete error:
Cannot convert null to 'myNameServer.myStructName' because it is a non-nullable value type

Use class instead of struct.

(temporary solution only, hopefully this post will be edited)

Enums in C#

correct usage:

class myClass
{
public enum myEnumType {Value1, Value2};
public myEnumType myEnumVariable;
}

class myOtherClass
{
public myFunction()
{
myClass foo = new myClass();
foo.myEnumVariable = myClass.myEnumType.Value1;
}
}

Monday, May 17, 2010

Number only text box - C# Express Edition

private void txt_FieldName_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b')
e.KeyChar = '\0';
}

Monday, April 12, 2010

DTS in SQL Studio 2008

Download here

1. Download and isntall the latest Microsoft SQL Server 2005 Backward Compatibility Components (It is for 2008 also)
2. Download and install the latest Microsoft SQL Server 2000 DTS Designer Components
3. Try right-clicking on a DTS package and select Open. If you still get the error, follow these steps:
a) Copy the files, SEMSFC.DLL, SQLGUI.DLL, and SQLSVC.DLL, from the %ProgramFiles%\Microsoft SQL Server\80\Tools\Binn folder to the %ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE folder.
b) Copy the files, SEMSFC.RLL, SQLGUI.RLL, and SQLSVC.RLL, from the %ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\Resources\1033 folder to the %ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Resources\1033 folder.
(Reference: http://msdn.microsoft.com/en-us/library/ms143755.aspx )

Tuesday, August 4, 2009

'CertificatePolicy is obsoleted for this type

Error message: 'System.Net.ServicePointManager.CertificatePolicy' is obsolete: 'CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead.' http://go.microsoft.com/fwlink/?linkid=14202

ServicePointManager.CertificatePolicy = new CustomCertificatePolicy();

modify to

ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback(CertValidation);

bool CertValidation(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslpolicyErrors)
{
bool result = false;
// TODO: implement
return result;
}

for example if you want to accept untrusted server certificate which I don't recommend :D use it like:

bool CertValidation(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslpolicyErrors)
{
bool result = false;
if ((chain != null) && (chain.ChainStatus.Length == 1) &&
(chain.ChainStatus[0].Status == X509ChainStatusFlags.UntrustedRoot))
result = true;
return result?result:sslpolicyErrors == SslPolicyErrors.None;
}

Monday, June 22, 2009

Thread was being aborted.

System.Threading.ThreadAbortException: Thread was being aborted.
occured on Response.Redirect(url) even when in a try catch block.

Asp.net framework catches the Redirect method's exception, aborts the thread and use a new thread for execution of the redirected page. This occurs when using the second argument of Redirect method as True, because this means to asp.net framework something like 'Stop this page's execution ASAP and execute to be redirected page'.

Response.Redirect method internally calls Response.End method which raises this exception and the page processing terminates. Response.End raises this exception indirectly through calling Thread.Abort which raises this exception directly.
When this exception occurs you can catch it in a catch block of a try...catch structure. The exception will be raised again by the runtime at the end of the catch block. So, no use of the try...catch block.

try to use Response.Redirect(url, false)

source http://p2p.wrox.com/asp-net-1-0-1-1-basics/5684-thread-being-aborted.html

Wednesday, January 14, 2009

Inexact float


I've found nothing to do about it.