Friday, November 26, 2010

"{"Attempt to access the method failed: System.IO.FileInfo..ctor(System.String)"}" on WP7

I got this error and had to crack my head to find out what went wrong. it was a simple mistake i did when i named the "WMInteropManifest.xml" but the correct name should be "WPInteropManifest.xml"

Tuesday, November 23, 2010

How to get the Domain Name by Controller Name or Server Name using C#

Today I ran into this problem and after few hours of googling i came up with this. Hope this will help someone as well.

static void Main() {

string domainservername = "xxx";
string domainusername = "xxx";
string domainpassword = "xxx";

Add reference to System.DirectoryServices.dll

DirectoryContext context = new DirectoryContext(DirectoryContextType.DirectoryServer, domainservername, domainusername, domainpassword);

DomainController controller = DomainController.FindOne(context);
string domainName = controller.Domain.Name;
}

Monday, November 22, 2010

How to determine the install directory of ASP.NET aspnet_regiis.exe ?

here is a cool tip to find the installed install directory of ASP.NET aspnet_regiis.exe

string aspNetInstallDir = HttpRuntime.ClrInstallDirectory;

Friday, November 19, 2010

Component SQL Server 2008 Express has failed to install with the following error message:

I was tring to deploy MS SQL Express 2008 SP 1 version as a merge module with my application.
When it's running on silent mode, it's not easy to find error messages thats greates errors like this.

easyest way to solve problem is goto Log directory located here

%programfiles%\microsoft sql server\100\setup bootstrap\log

and sort the folders by date and check the latest one

Error: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM

I got this error few days back when i was using SubSonic to do some Database updates. Most of the time this error occures if.

1. Date Time Format is wrong. - Always stick to yyyy-MM-dd format. it will makes life so easy
2. Check for current culture for the execution thread. if it's running in a different culture thread this error is likely to occur

Process exited with code -2068578301

Most of the time this error occures if your SQL Server instance name is greater than 16 characters.
Instance names are limited to 16 characters.

WinForms Wait Screen in C#

I know there are lots of waiting screens for Web UIs but this one for WinForms using Windows Applications

Special Thanks to Microsoft !

Public class WaitScreen
{
// Fields
private object lockObject = new object();
private string message = "Please Wait...";
private Form waitScreen;

// Methods
public void Close()
{
lock (this.lockObject)
{
if (this.IsShowing)
{
try
{
this.waitScreen.Invoke(new MethodInvoker(this.CloseWindow));
}
catch (NullReferenceException)
{
}
this.waitScreen = null;
}
}
}

private void CloseWindow()
{
this.waitScreen.Dispose();
}

public void Show(string message)
{
if (this.IsShowing)
{
this.Close();
}
if (!string.IsNullOrEmpty(message))
{
this.message = message;
}
using (ManualResetEvent event2 = new ManualResetEvent(false))
{
Thread thread = new Thread(new ParameterizedThreadStart(this.ThreadStart));
thread.SetApartmentState(ApartmentState.STA);
thread.Start(event2);
event2.WaitOne();
}
}

private void ThreadStart(object parameter)
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
ManualResetEvent event2 = (ManualResetEvent) parameter;
Application.EnableVisualStyles();
this.waitScreen = new Form();
this.waitScreen.Tag = event2;
this.waitScreen.ShowIcon = false;
this.waitScreen.AutoSize = true;
this.waitScreen.AutoSizeMode = AutoSizeMode.GrowAndShrink;
this.waitScreen.BackColor = SystemColors.Window;
this.waitScreen.ControlBox = false;
this.waitScreen.FormBorderStyle = FormBorderStyle.FixedToolWindow;
this.waitScreen.StartPosition = FormStartPosition.CenterScreen;
this.waitScreen.Cursor = Cursors.WaitCursor;
this.waitScreen.Text = SR.WaitScreenTitle;
this.waitScreen.FormClosing += new FormClosingEventHandler(this.WaitScreenClosing);
this.waitScreen.Shown += new EventHandler(this.WaitScreenShown);
Label label = new Label();
label.Text = this.message;
label.AutoSize = true;
label.Padding = new Padding(20, 40, 20, 30);
this.waitScreen.Controls.Add(label);
Application.Run(this.waitScreen);
Application.ExitThread();
}

private void WaitScreenClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
}
}

private void WaitScreenShown(object sender, EventArgs e)
{
Form form = (Form) sender;
form.Shown -= new EventHandler(this.WaitScreenShown);
ManualResetEvent tag = (ManualResetEvent) form.Tag;
form.Tag = null;
tag.Set();
}

// Properties
public bool IsShowing
{
get
{
return (this.waitScreen != null);
}
}
}


-------------------
How to use
-------------------

WaitScreen waitScreen = new WaitScreen();
waitScreen.Show("Please wait for me!");

Friday, November 12, 2010

Things I learn new this week

1. Never ever use WCF.
---------------------

here is why
1. IIS 7 doesn't support .svc file format by default. So you need to install some extension files. so it's lot of work for a new product.

2. I found it very hard to configure security settings. when i tried to configure for the first time it threw all kind of errors.

3. After installing WCF in IIS, sometimes it's trowing an exception that refers to the temp directory. To solve this problem you have to re compile the application and re-distribute

and a lot more...


2. Deploying digitalpersona for Window 7 64bit.
-------------------------

this can be easy but tricky, here is why.

if you are trying to install digitalpersona dlls to a fresh Windows 7 64-Bit PC you should include
DpCore.msm module because this module contains the core files like dphost.exe. surprisingly they have not included those files in DpCore_x64.msm. Dphost to this day remains 32 bit, which is why you need to install both modules. The 64bit module contains some dlls necessary for your 64bit application to communicate with dphost.

3. install location for prerequisites has not been set to 'component vendor's web site' and the file 'SqlExpress2008\SQLEXPR32_x86_ENU.EXE' in item 'SQL Server 2008 Express' can not be located on disk. See Help for more information.

do solve this , you need to download sqlexpr32_x86_enu.exe and place it in
C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\SqlExpress2008\en

4. most of the time when we want to do something small, we write a function. I found this nice piece of code to support kind of inline function

Action d = (bool x) =>
{
var win = MainWindow as MainWindow;
if (win == null) return;
win.ApendArgs(args.CommandLineArgs);
win.Activate(x);
};

Dispatcher.Invoke(d, true);

// or

d.Invoke(true);