Sunday, November 30, 2014

My pet project Android Web Terminal

My pet project Android Web Terminal was homeless for few months. I found a new home and everyone is welcome http://www.androidwebterminal.com/

Wednesday, November 16, 2011

Failed to connect to the device. Ensure that the device is completely booted and is connected to the PC.

Today I got this error when I updated the phone from Windows Phone 7 to 7.5 (Mango)

To solve this, I had to change the project settings to use the Target Operating system to 7.1 All worked!

Friday, October 28, 2011

How to download full-version of skype ?

http://www.skype.com/go/downloading?source=lightinstaller&ver=5.5.0.124.259&LastError=12002

Tuesday, April 26, 2011

Reference to class 'xxx' is not allowed when its assembly is linked using No-PIA mode

To fix this error you need to Change the Embed Interop Type to false in the properties of the reference.

Could not load file or assembly or one of its dependencies. An attempt was made to load a program with an incorrect format. in VB.NET 2010

Could not load file or assembly 'Interop.PortableDeviceApiLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. ?

Today, I wanted to add PortableDeviceApiLib assembly to my project to pull some information from a iPhone device. After I add reference to the dll. I started getting this issue. To fix this you need to change the Platform to x86

Project Properties> Build > Target Platform to "x86"

strange solution, but it works.

Monday, January 31, 2011

Web page to access clipboard exception with Watin

I have been working on a solution to get the clipboard working with Watin automated program. because security exception is really annoying!

here is goes,

class Program
{
[STAThread]
static void Main(string[] args) {


SecurityAlertDialogHandler securityAlertDialogHandlerMock = new SecurityAlertDialogHandler();

using (IE ie = new IENoWaitForComplete("url goes here")) {

ie.AddDialogHandler(securityAlertDialogHandlerMock);

//GetPicture(ie.Images[0], ie);
ie.WaitForComplete();

IEElement banner = ieImages[0].NativeElement as IEElement;

IHTMLElement bannerHtmlElem = banner.AsHtmlElement;
IEElement bodyNative = ie.Body.NativeElement as IEElement;
mshtml.IHTMLElement2 bodyHtmlElem = (mshtml.IHTMLElement2)bodyNative.AsHtmlElement;
mshtml.IHTMLControlRange controlRange = (mshtml.IHTMLControlRange)bodyHtmlElem.createControlRange();

controlRange.add((mshtml.IHTMLControlElement)bannerHtmlElem);
controlRange.execCommand("Copy", false, System.Reflection.Missing.Value);
controlRange.remove(0);

if (Clipboard.GetDataObject() != null) {
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(DataFormats.Bitmap)) {
System.Drawing.Image image = (System.Drawing.Image)data.GetData(DataFormats.Bitmap, true);
// do something here
}
}
}
}

}

class IENoWaitForComplete : IE
{
public IENoWaitForComplete(string url) : base(url) { }

public override void WaitForComplete(int timeOutPeriod) {
// Skip Wait logic
}
}

class SecurityAlertDialogHandler : BaseDialogHandler
{
private bool _hasHandledSecurityAlertDialog;

public bool HasHandledSecurityAlertDialog {
get { return _hasHandledSecurityAlertDialog; }
}

public override bool HandleDialog(Window window) {
new WinButton(1, window.Hwnd).Click();
return true;
}

public override bool CanHandleDialog(Window window) {
return window.StyleInHex == "94C808CC";
}

}

Tuesday, January 25, 2011

C# Enum.prase in Java or Enum valueOf in C#

this is how to use it in Java

Java
------
public enum Direction {
NORTH, SOUTH, EAST, WEST
}

Direction home = Direction.valueOf(“SOUTH”);

C#
------

System.Enum.Parse(typeof(Direction), "SOUTH",true);

varibale++ vs ++varibale confustion in Java

I just noticed that variable name ++ assignments can be bit confusing (may be due to the fact that I have been a Microsoft based programmer from almost 10 years).

here goes.

Eg,

int r = 4;
int result = r++;

guess whats the result value going to be? it is still 4. Because Java won't perform the actual calculation of the operator until you use variable r somewhere in the code.

however if you use

int r = 4;
int result = ++r;

this will perform the arithmetic operation inline and return the result to 'result' variable.

Friday, January 14, 2011

C# Format.String ( {0} ) equivalent in Java ?

Last few days I have been learning Java. When i used C#, String.Format({0}) was one of my favorites and I was wondering how to do this in Java.

String.format("some string here %s ", valuehere);

Thursday, January 06, 2011

How to fix Eazfuscator.NET unhandled exception error in WPF?

Today, I wanted to obfuscate one of the WPF applications that we are planing to deploy soon. While
googling I found this grate open source product Eazfuscator.NET and I downloaded the latest beat version and gave it a try.

After the obfuscating process completed I ran the .exe file to check whether everything is working as it suppose to but it didn't and I got this exception instead.

"Description: The process was terminated due to an unhandled exception. Exception Info: System.Windows.Markup.XamlParseException"

Now confused. I had no idea how to fix it ! googled it again and got nothing! So i decided to play around it and see.

1. Create a separate window. set it as the start-up Url in App.xaml file Eg,
StartupUri="DummyWindow.xaml"

2. If it's working, which it did for me.

3. Try looking at the MainWindow.xaml event bindings with the MainWindow.xaml.cs file.

most if the time, when it obfuscates, it will obfuscates events as well, If you have any events Like
Window_Loaded make sure they are not being obfuscated using the flag

[System.Reflection.Obfuscation(Exclude = true)]

Eg.

[System.Reflection.Obfuscation(Exclude = true)] private void Window_Loaded(object sender, RoutedEventArgs e) {

}


4. Open the VS 2010 editor, Change it to release mode and rebuild.

you should see a message like,

Obfuscating assembly 'xxxxx.exe'...

then run, You should get an error message if you have any problems starting up which should be easy to diagnose.

Hope this will help someone. Eazfuscator.NET is a grate free product and I hope it will stay that way !


Monday, December 13, 2010

why 'EasingDoubleKeyFrame' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'.

if you get this error that means you are trying to use a WPF4 feature in 3.5

easyway out is to change it to change it to SplineDoubleKeyFrame

how to solve The attachable property 'VisualStateGroups' was not found in type 'VisualStateManager'. exception in VS2008

No need to move to VS2010 to solve this problem,

just have to install these two patches to get the VisualStateGroups in XAML view

http://code.msdn.microsoft.com/KB958017/Release/ProjectReleases.aspx?ReleaseId=1719
http://code.msdn.microsoft.com/KB958017/Release/ProjectReleases.aspx?ReleaseId=1719

then it works like a magic.

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);