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

http://social.microsoft.com/Forums/en-US/windowsmobileactivesync/thread/56e1b653-ec2a-48d8-9b2e-b6c95a2f2284

 

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

I continuing getting an exception in our Silverlight project:
"C# A first chance exception of type 'System.NotSupportedException' occurred in mscorlib.dll"

Thanks for Sandrino who save my life by posting your solution:

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:

  1. - Open solution in blend (nothing showing in project tab)
  2. - Go to “File” => “Close Project” (I am surprising that projects are opened)
  3. - “File” => “Open Project”, navigate you solution file, open it.
  4. - Now it should load all projects for you.


Here is the issue I just reported:

http://social.expression.microsoft.com/Forums/en-US/blend/thread/711fd369-d940-4933-9ba6-3992f9309eab


Hope someone found a better solution or Blend 4 team could fix this bug.

Sunday, April 11, 2010

Visual Studio 2010 offically released

 

Visual Studio 2010 officially released today. However, Silverlight 4 has not been delivered at same time. It will be available later this week.

 

Check out:

http://www.microsoft.com/visualstudio/en-us/

Friday, April 9, 2010

Error message when load assembly in Visual Studio 2010 Silverlight 4 project

Error 1 The "ValidateXaml" task failed unexpectedly.
System.IO.FileLoadException: Could not load file or assembly 'XXX.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'XXX.dll' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.


A solutions posted by krohling here:

Microsoft Silverlight Media Framework - Discussions - SL4 Support:

Right click on each ***.dll file in Windows Explorer
Uncheck 'Read Only'
Click 'Unblock'

I believe this is because Windows does not initially trust files that you download from the internet.

For additional information about this: http://www.petri.co.il/unblock-files-windows-vista.htm

Friday, February 26, 2010

SQL Server Trigger to tracking last data updates

USE Northwind;
GO
IF
OBJECT_ID ('TableUpdateTrigger','TR'
) IS NOT NULL
DROP TRIGGER TableUpdateTrigger
;
GO

CREATE TRIGGER
TableUpdateTrigger
ON Categories
AFTER INSERT, UPDATE,
DELETE
AS
IF
NOT EXISTS (SELECT * FROM zzzTableUpdates WHERE TableName='Categories'
)
INSERT INTO zzzTableUpdates (TableName, LastUpdate) Values ('Categories', GETDATE
())
ELSE
UPDATE
zzzTableUpdates SET LastUpdate=GETDATE() WHERE TableName=
'Categories'
GO


Tuesday, February 9, 2010

.NET Windows Form - Display the standard DataLink property dialog box as child window of current form

Want to shared some of my experience to use DataLink form to edit database connection string in windows form application.

The hardest part is to set DataLink form as child window of current form. But fortunately, I find a way to set HWnd property to get it solved.

Here is the code:

  1: Public Function GetConnection() As String
  2:     Dim dc As MSDASC.DataLinks = New MSDASC.DataLinksClass()
  3:     Dim oConnection As Object = GetFakeOledbConnectionString(existingConnectionString)
  4:     dc.hWnd = Me.Handle    '//Set parent window to current form    
  5:     If dc.PromptEdit(oConnection) Then
  6:        Return CType(oConnection, ADODB._Connection).ConnectionString
  7:     Else
  8:        Return Nothing
  9:     End If
 10: End Function
 11: 
 12: Private Function GetFakeOledbConnectionString(ByVal str As String) As Object
 13:     If String.IsNullOrEmpty(str) Then
 14:         str = "Integrated Security=SSPI; Persist Security Info=True;Password=1;"
 15:     End If
 16:     If Not str.StartsWith("Provider", StringComparison.OrdinalIgnoreCase) Then
 17:         str = "Provider=SQLOLEDB;" + str
 18:         str = str.Replace("Integrated Security=True", "Integrated Security=SSPI")
 19:         If Not str.ToLower().Contains("Persist Security Info".ToLower()) Then
 20:             str = str.TrimEnd(" ").TrimEnd(";") + "; Persist Security Info=True;"
 21:         End If
 22:     End If
 23:     Dim position As Integer = str.IndexOf("AttachDBFile", StringComparison.OrdinalIgnoreCase)
 24:     If position > 0 Then
 25:         str.Replace("AttachDbFilename=;", "")
 26:     End If
 27:     Dim adoConnection As ADODB._Connection = New ADODB.ConnectionClass()
 28:     adoConnection.ConnectionString = str    
 29:     Return adoConnectionEnd 
 30: Function

Tuesday, February 2, 2010

Silverlight: how to update UI before time comsumming process

 

I was trying to make my Silverlight application to update UI before start a time consuming process. For some reason, I can use put that process in new thread. So I have to implement some technique as following:

 

    this.UpdateLayout(); //I want UI update before start that process

    new Thread(() =>

    {

        Thread.Sleep(100);  //Update UI first

        this.Dispatcher.BeginInvoke(() =>

        {

            //Long time process, which stop UI updates

        });

    }).Start();

Wednesday, January 20, 2010

Problem with varchar(max) via SQL Native Client

Having issue with retrieve data from varchar(max) field. This is turned out a problem with SQL Native Client. Tried to use “SQL Server Native Client 10.0”, with same result.

Than I have to revert back to use “SQL Server” driver, which doesn’t has performance as good as SQL Native Client driver.

Hope Microsoft will fix it some day.

Here is the link of bug reported: https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=467300&wa=wsignin1.0

Sunday, January 17, 2010

How do I fix IE8 not open link problem

I fix the problem by doing following steps:

Quoted from: http://social.answers.microsoft.com/Forums/en-US/InternetExplorer/thread/e312e580-1cbc-496b-8c6b-b69b8535a7bb


Updates: new version script from:

http://iefaq.info/index.php?action=artikel&;cat=42&id=133&artlang=en

Thanks for OnyXxL to provide the solution.

Hi,

I followed a tip given by Pbell on this forum. Originally, it was made to resolve problems on IE8 32 bits when you use a 32 bits OS. I changed "%ProgramFiles(x86)%" var, and now my issue is resolved for IE8 32 bits on my Windows 7 64 bits. Please try it, and tell me if everything work for you.

For Win 7 64 bits :

1 - Create a new notepad document and paste this text :

@echo off
echo.
echo IEREREG Version 1.07 for IE8 27.03.2009
echo by Kai Schaetzl
http://iefaq.info
echo installs and registers (if suitable) all DLLs known to be used by IE8.
echo should only take a few seconds, but please be patient
echo.
REM ******************************
echo registering IE files
REM IE files (= part of setup)
regsvr32 /s /i browseui.dll
REM regsvr32 /s /i browseui.dll,NI (unnecessary)
regsvr32 /s corpol.dll
regsvr32 /s dxtmsft.dll
regsvr32 /s dxtrans.dll
REM simple HTML Mail API
regsvr32 /s "%ProgramFiles(x86)%\internet explorer\hmmapi.dll"
REM group policy snap-in
regsvr32 /s ieaksie.dll
REM smart screen
regsvr32 /s ieapfltr.dll
REM ieak branding
regsvr32 /s iedkcs32.dll
REM dev tools
regsvr32 /s "%ProgramFiles(x86)%\internet explorer\iedvtool.dll"
regsvr32 /s iepeers.dll
REM Symptom: IE8 closes immediately on launch, missing from IE7
regsvr32 /s "%ProgramFiles(x86)%\internet explorer\ieproxy.dll"
REM no install point anymore
REM regsvr32 /s /i iesetup.dll
REM no reg point anymore
REM regsvr32 /s imgutil.dll
regsvr32 /s /i /n inetcpl.cpl
REM no install point anymore
REM regsvr32 /s /i inseng.dll
regsvr32 /s jscript.dll
REM license manager
regsvr32 /s licmgr10.dll
REM regsvr32 /s msapsspc.dll
REM regsvr32 /s mshta.exe
REM VS debugger
regsvr32 /s msdbg2.dll
REM no install point anymore
REM regsvr32 /s /i mshtml.dll
regsvr32 /s mshtmled.dll
regsvr32 /s msident.dll
REM no reg point anymore
REM regsvr32 /s msrating.dll
REM multimedia timer
regsvr32 /s mstime.dll
REM no install point anymore
REM regsvr32 /s /i occache.dll
REM process debug manager
regsvr32 /s "%ProgramFiles(x86)%\internet explorer\pdm.dll"
REM no reg point anymore
REM regsvr32 /s pngfilt.dll
REM regsvr32 /s /i setupwbv.dll (not there anymore!)
regsvr32 /s tdc.ocx
regsvr32 /s /i urlmon.dll
REM regsvr32 /s /i urlmon.dll,NI,HKLM
regsvr32 /s vbscript.dll
REM VML renderer
regsvr32 /s "%CommonProgramFiles%\microsoft shared\vgx\vgx.dll"
REM no install point anymore
REM regsvr32 /s /i webcheck.dll
regsvr32 /s /i /n wininet.dll
REM ******************************
echo registering system files
REM additional system dlls known to be used by IE
REM added 11.05.2006 Symptom: Add-Ons-Manager menu entry is present but nothing happens
regsvr32 /s extmgr.dll
REM added 12.05.2006 Symptom: Javascript links don't work (Robin Walker) .NET hub file
regsvr32 /s mscoree.dll
REM added 23.03.2009 Symptom: Find on this page is blank
regsvr32 /s oleacc.dll
REM added 24.03.2009 Symptom: Printing problems, open in new window
regsvr32 /s ole32.dll
REM mscorier.dll
REM mscories.dll
REM Symptom: open in new tab/window not working
regsvr32 /s actxprxy.dll
regsvr32 /s asctrls.ocx
regsvr32 /s cdfview.dll
regsvr32 /s comcat.dll
regsvr32 /s /i /n comctl32.dll
regsvr32 /s cryptdlg.dll
regsvr32 /s /i /n digest.dll
regsvr32 /s dispex.dll
regsvr32 /s hlink.dll
regsvr32 /s mlang.dll
regsvr32 /s mobsync.dll
regsvr32 /s /i msieftp.dll
REM regsvr32 /s msnsspc.dll #no entry point
regsvr32 /s msr2c.dll
regsvr32 /s msxml.dll
regsvr32 /s oleaut32.dll
REM regsvr32 /s plugin.ocx #no entry point
regsvr32 /s proctexe.ocx
REM plus DllRegisterServerEx ExA ExW ... ?
regsvr32 /s /i scrobj.dll
REM shdocvw.dll hasn't been updated for IE7 and IE8, it still registers itself for the Windows Internet Controls
regsvr32 /s /i shdocvw.dll
regsvr32 /s sendmail.dll
REM ******************************
REM PKI/crypto functionality
REM initpki can take very long to run and is rarely a problem
REM if there are problems with crypto, SSL, certificates
REM remove the three following REMs from the lines
REM echo We are almost done except one crypto file
REM echo but this will take very long, be patient!
REM regsvr32 /s /i:A initpki.dll
REM ******************************
REM tabbed browser, do at the end, why originally with /n ?
regsvr32 /s /i ieframe.dll
REM ******************************
echo correcting bugs in the registry
REM do some corrective work
REM Symptom: new tabs page cannot display content because it cannot access the controls (added 27. 3.2009)
REM This is a result of a bug in shdocvw.dll (see above), probably only on Windows XP
reg add "HKCR\TypeLib\{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}\1.1\0\win32" /ve /t REG_SZ /d %systemroot%\system32\ieframe.dll /f
REM ******************************
echo all tasks have been finished
echo.
pause

2 - Close all your IE windows and processes.
3 - Save your document on your Desktop by example, with the .bat extension. Right-click on it, and select "Run as administrator".
4 - Test if this tip resolved your issue by openning IE. If you use a Windows 32 bits version, please replace
%ProgramFiles(x86)% by %ProgramFiles% in your .bat file.

OnyXxL