Wednesday, May 12, 2010

.NET 4.0 "dynamic" keyword versus, "var" keyword - anonymous types

The "dynamic" keyword in .NET 4.0.

What is really cool about this keyword is that the actual type attached to your variables is applied at run-time without needing to worry about properties, methods, etc.  Very cool.  Below will be an explanation of this in a little more detail.


The "var" keyword
First you may think that this is just another way to implement the "var" keyword, but this is not true.  The "var" keyword is very different then the "dynamic" keyword.  The "var" keyword does not have the ability to be passed as a parameter to a method or as a return type.

Now one could argue that you can do this by boxing or why you would want to do this in the first place, but this is purely just to show the differences.  In addition, the "var" keyword is strictly typed so when the compiler reaches this line of code it will perform the proper type casting for you and determine if the expression is correct.

For example the following line of code will show a compile error as highlighted in red:















Because the compiler is strictly typing this anonymous type it determines that the method does not exist and causes an error when trying to compile.  Now you can get around this by using reflection or an object, but for this example it is just to show the differences, not so much how to make another way work or not work.

Now let's take a look at the "dynamic" keyword. 

For this example we will take the same example as above and see if this compiles using a dynamic anonymous type.  Furthermore, we will even call a method that we know does not exist in the class.















As you can see with this example the compiler does not check this anonymous type at all or the properties or methods to see if they exist.  It will however dynamically type cast this at run-time.

Summary
In summary, the "var" keyword is an anonymous type and will always be derived from the base object class directly.  Whereas, the "dynamic" type will be handled at run-time allowing for more flexibility at the cost of intellisense.

With all that said, this could be looked at as very dangerous coding.  However, when using objects that are dynamic this could be very handy if used properly.  I could think of a few areas to use this, such as with Web Services where you do not have the WSDL yet, but would like to complete the coding, or legacy COM objects where the properties are dynamic themselves.

I plan to perform some benchmark tests to see if using this has performance impacts and will update my blog when finished.

All comments are welcome.

Tuesday, May 11, 2010

TFS 2010 server licensing: It's included in MSDN subscriptions

Very good news for the development community. It appears as though Team Foundation Server and Team System are now included with an MSDN subscription. Great information can be found from the MSDN blog site.

TFS 2010 server licensing: It's included in MSDN subscriptions


Cited from "Buck Hodges" blog on MSDN.

Fiddler Web Debugger BETA 2.2.9 is now available

Fiddler Web Debugger BETA 2.2.9 is now available

Download Here: Fiddler

Thursday, May 6, 2010

Microsoft SQL Azure Quick Tips Link

This is a great link to a number of exercises you may need to do with SQL Azure.

http://blogs.msdn.com/sqlazure/archive/2010/05/06/10007449.aspx

The main one I was interested in was the one related to SSIS.

Exercise 3: Using SSIS for Data Import and Export

Windows Azure - Dr. Watson Diagnostic ID - Error and Potential Solution

I noticed that when using the Staging environment within Windows Azure that the GUID or unique ID that was created for the deployment may in some cases become corrupt.

I found a work around for this issue by simply stopping the service, deleting it, and then re-adding the service back again. What I found is that in some cases the deployment ID or package can become corrupt and when you upgrade the package and config files the site is still in operable.

I received many different errors during the process, such as Dr Watson, Role Not found, etc. Once I recreated the entire staging service everything was fine.

Just figured I would post this if others notice this similar issue. I also, noticed that the Azure service re-purposed another Staging URL(GUID) from another client as I was able to see certain information that was not related to my site at all. Once the refresh was in affect the content was updated correctly, but while the update was happening I saw the other site's content.

Wednesday, May 5, 2010

Errors with Microsoft SQL Azure Data Sync Tools

SQL Azure Data Sync Microsoft Error Information
ONCE MICROSOFT Provides me with a solution or I figure out how to resolve this issue,  I will update the
blog accordingly.
1.                  Detailed description of the issues that you are experiencing ?
a.       I am unable to use the Azure Data Sync Tool to synchronize data from my local database to SQL Azure.  I receive several errors such as file not found and app error.

2.                  What operations were performed before seeing this issue?
a.       I get to the point where the utility is about to synchronize the data after I select my tables and order it fails.

6.                  Please send us the screen shots of the errors which will help us to expedite investigation.







System.IO.FileNotFoundException was unhandled
  Message=Could not load file or assembly 'Microsoft.Synchronization.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
  Source=PublishWizard
  FileName=Microsoft.Synchronization.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
  FusionLog=WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

  StackTrace:
       at DNBSoft.WPF.ProceedureDialog.ProceedureDialog.finishButton_Click(Object sender, RoutedEventArgs e)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.Controls.Primitives.ButtonBase.OnClick()
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at SampleApplication.EntryPoint.Main(String[] args)
  InnerException:


Again once I will make updates to this post once I determine a solution or Microsoft provides one to me.

Tuesday, May 4, 2010

Accessing Data in SQL Azure



In a traditional on-premise application, the application code and database are located in the same physical data center. SQL Azure and the Windows Azure platform offer many alternatives to that architecture. The following diagram demonstrates two generalized alternatives available for how your application can access data with SQL Azure.
Access SQL Azure from 
client premesis or the cloud
In Scenario A on the left, your application code remains on the premises of your corporate data center, but the database resides in SQL Azure. Your application code uses client libraries to access your database(s) in SQL Azure. For more information about the client libraries that are available, see Guidelines and Limitations (SQL Azure Database). Regardless of the client library chosen, data is transferred using tabular data stream (TDS) over a secure sockets layer (SSL).
In Scenario B on the right, your application code is hosted in the Windows Azure and your database resides in SQL Azure. Your application can use the same client libraries to access your database(s) in SQL Azure as are available in Scenario A. There are many different types of applications that you can host in the Windows Azure platform.
The Scenario B client premises may represent an end user's Web browser that is used to access your Web application. The Scenario B client premises may also be a desktop or Silverlight application that uses the benefits of the Entity Data Model and the WCF Data Services client to access your data that is hosted in SQL Azure.
For more information about the SQL Azure architecture, see SQL Azure Architecture.

 Cited from Microsoft's Site: http://msdn.microsoft.com/en-us/library/ee336239.aspx

Transact-SQL Reference (SQL Azure Database)

http://msdn.microsoft.com/en-us/library/ee336281.aspx