Visual Studio 2010 – Visual Basic New Feature – NonSerialized Events

A long time feature request has been added to Visual Basic 10 that ships with Visual Studio 2010; decorating an Event as NonSerialized.

In prior versions of Visual Basic developers had to implement a Custom Event or another workaround when their types needed to expose an Event and they had to be Serializable.  C# had this capability, now Visual Basic does too!

A very common scenario is a class that implements INotifyPropertyChanged and must also be Serializable. 

Visual Basic developers can now decorate the Event with the NonSerialized attribute.  The compiler does the rest for you.

Imports System.ComponentModel

<Serializable()>
Public Class Customer
    Implements INotifyPropertyChanged

#Region " INotifyPropertyChanged Serializable "

    'New VB 10 feature!
    <NonSerialized()>
    Public Event PropertyChanged(
                  ByVal sender As Object,
                  ByVal e As System.ComponentModel.PropertyChangedEventArgs) _
                  Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged

    Protected Sub OnPropertyChanged(ByVal strPropertyName As String)
        If Me.PropertyChangedEvent IsNot Nothing Then
            RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(strPropertyName))
        End If
    End Sub

#End Region

End Class

Have a great day,

Just a grain of sand on the worlds beaches.

5 Responses to Visual Studio 2010 – Visual Basic New Feature – NonSerialized Events

  1. blogdotonyhenrique says:

    Karl, i am had some problems with WPF and XBAP hanging. Please dont forget the programmers like me that are using XBAP.

  2. blogdotonyhenrique says:

    I have an ASP.Net system, and I am replacing some screens with XBAP for speed improvement.
    But i am having some problem with some bugs on WPF and XBAP, and the XBAP initialize time. verifying requirements,etc.
    Some times, when user is moving mouse ou typing the XBAP hangs the browser window. I am also having problems with NavigationService.Navigate, to a page with javascript parent.location =’www.google.com’ when called from xbap, it opens a new window instead of opening it on parent.

    I was using Beta 1. And XBAP stopped working after installed .Net Framework 4 Beta 2 . When i uninstall Beta 2, the XBAP works again.

    On Beta 1 I also had problem with another bug. If you see the stack trace you can see that the XBAP throws this exception even before hitting my code.
    If i try 3 times, then the XBAP open:
    Sometimes when opening a XBAP an erros happen

    System.InvalidOperationException: No further operations are possible with this instance.

    at System.Deployment.Application.InPlaceHostingManager.AssertState(State validState)
    at System.Deployment.Application.InPlaceHostingManager.Execute()
    at MS.Internal.AppModel.XappLauncherApp.ExecuteDownloadedApplication()
    at System.Windows.Interop.DocObjHost.RunApplication(ApplicationRunner runner)
    at MS.Internal.AppModel.XappLauncherApp.XappLauncherApp_Exit(Object sender, ExitEventArgs e)
    at System.Windows.Application.OnExit(ExitEventArgs e)
    at System.Windows.Application.DoShutdown()
    at System.Windows.Application.ShutdownImpl()
    at System.Windows.Application.ShutdownCallback(Object arg)
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
    at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Boolean isSingleParameter, Delegate catchHandler)
    at System.Windows.Threading.DispatcherOperation.InvokeImpl()
    at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
    at System.Threading.ExecutionContext.runTryCode(Object userData)
    at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Windows.Threading.DispatcherOperation.Invoke()

  3. [...] Visual Studio 2010 – Visual Basic New Feature – NonSerialized Events (Karl Shifflett) [...]

Follow

Get every new post delivered to your Inbox.

Join 167 other followers