Andy Li
Andy's .net programming blog
Saturday, November 27, 2010
Monday, August 16, 2010
Monday, August 9, 2010
How to initialze an generic Type by default constructor
class Program
{
static void Main(string[] args)
{
var testObj = BuildGenericType<TestClass>();
testObj.Member1 = "tgest";
Console.WriteLine(testObj.Member1);
Console.Read();
}
static T BuildGenericType<T>()
{
var cInfo = typeof(T).GetConstructor(new Type[] { });
T targetObj = (T)cInfo.Invoke(new object[] { });
return targetObj;
}
class TestClass
{
public string Member1;
public int Member2;
}
}
Tuesday, May 11, 2010
Can't connect with WMDC - Windows Mobile-based device failed to connect due to communication (0x80072745) failure
This is a workaround for this problem.
After a lot of changes i realize that the problem is with the Windows Portable Device. I am using a Windows Server 2008 as my workstation. When a lot of people try to troubleshoot this problem, they always talked about this driver but this is not showed under W2k8 Server.
I have a W2k8 Server 32 bits with no problem at all where Portable Device is not showed, the problem is in my other pc with W2k8 Server 64 bits where Portable Device is not showed too.
So, what i did is forcing the OS to install the Windows Portable Device Driver doing this:
- Server Manager
- Device Manager
- Add Legacy hardware
- Browse my computer for driver software
- Let me pick from a list of device drivers in my computer
- Select Windows Mobile-base device (look up for the "-". If you dont have it that means that you dont have the last version of WMDC)
- And Next
- Finally, Connect your device and restart the PC
You will notice that the WMDC will work after the restart with some hicups like:
- You will lose the connection when you disconnect the device. Reconnecting is not a solution. You have to logof and login again
- This only works with Professional devices. WM Standard Edition devices wont work.
- The icon of your device won't show correctly when you change the device.
- You can "update driver" of the Windows Portable Device that you added in order to see that the name of your device is showed. If you dont do this, you will see the name of the first device that you connect.
In conclusion, i think there is a service that is not working fine handling the discovery of the WM device. Definitively, this is not a problem of Windows Firewall or any Antivirus. The solution for this is to diagnose the service in charge of auto discovery the device.
This never happened to me in other OS, just in this Win2k8 Server 64 bits.
Thursday, April 29, 2010
Silverlight 4: Watermark property for TextBox control has not implemented.
//
// Summary:
// Gets or sets the content displayed as a watermark in the System.Windows.Controls.TextBox
// when it is empty.
//
// Returns:
// The content displayed as a watermark in the System.Windows.Controls.TextBox
// when it is empty.
//
// Exceptions:
// System.NotImplementedException:
// API is not supported by the current platform variation.
[EditorBrowsable(EditorBrowsableState.Never)]
public object Watermark { get; set; }
Tuesday, April 20, 2010
Free Silverlight 4 Training Course
http://channel9.msdn.com/learn/courses/Silverlight4/
It’s nice to be free
Monday, April 19, 2010
A first chance exception of type 'System.NotSupportedException' occurred in mscorlib.dll
Let's say you have this in your configuration file:
metadata=res://*/MyEntities.csdl|res://*/MyEntities.ssdl|res://*/MyEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;Initial Catalog=Db;Integrated Security=True;MultipleActiveResultSets=True"
And let's say your ObjectContext (in our case MyEntities) is located in the assembly: Company.Application.Repositories.
Well, then you should replace the wildcard with the assembly name in the path of the resources.
Example:
metadata=res://Company.Application.Repositories/MyEntities.csdl|res://Company.Application.Repositories/MyEntities.ssdl|res://Company.Application.Repositories/MyEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;Initial Catalog=Db;Integrated Security=True;MultipleActiveResultSets=True"
Sunday, April 18, 2010
Blend 4 RC could not load silverlight projects solution
I had just upgrading my Silverlight projects from VS2008 to VS2010, has latest Silverlight tool 4 installed. To support Silverlight 4 project editing, I also installed Blend 4 Release Candidate (RC). The upgrading projects went very smooth, and Silverlight application runs great in VS2010.
However, when I trying to open a XAML file in Blend 4 from VS2010, Blend 4 give a few project not support warning message, and then stop loading projects. I couldn’t find any project files in project tab.
After a few time trying, found an workaround:
- - Open solution in blend (nothing showing in project tab)
- - Go to “File” => “Close Project” (I am surprising that projects are opened)
- - “File” => “Open Project”, navigate you solution file, open it.
- - Now it should load all projects for you.
Here is the issue I just reported:
Hope someone found a better solution or Blend 4 team could fix this bug.