none
Upgrading to .NET 4.0 generates SerializationException during execution RRS feed

  • Question

  • I just tried to transfer some code from .NET 3.5 to 4.0, and now during execution I get an error.

    if (PluginDomain == null)
    { AppDomainSetup ads = new AppDomainSetup();
    ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
    ads.PrivateBinPath = System.IO.Path.GetDirectoryName(System.IO.Path.GetFullPath(filename));
    PermissionSet ps = new PermissionSet(null);
     ps.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
    PluginDomain = AppDomain.CreateDomain("New AD", null, ads, ps);
    }

    DemuxerX pc = PluginDomain.CreateInstanceAndUnwrap(container.Assembly.FullName, container.FullName, false, 0, null, new object[] { t }, null, null, null) as DemuxerX;

    the "pc"'s constructor is called, and after that, this exception pops up:

    System.Runtime.Serialization.SerializationException was unhandled
      Message=Type 'MS.Internal.Permissions.UserInitiatedRoutedEventPermission' in Assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
      Source=mscorlib
      StackTrace:
           at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
           at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
           at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
           at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
           at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
           at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
           at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
           at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeObject(Object obj, MemoryStream stm)
           at System.AppDomain.Serialize(Object o)
           at System.AppDomain.MarshalObject(Object o)
           at System.Threading.CompressedStack.GetDomainCompressedStack(SafeCompressedStackHandle compressedStack, Int32 index)
           at System.Security.PermissionListSet.CreateCompressedState(CompressedStack cs, CompressedStack innerCS)
           at System.Threading.CompressedStack.CompleteConstruction(CompressedStack innerCS)
           at System.Threading.CompressedStack.GetCompressedStack(StackCrawlMark& stackMark)
           at System.Security.SecurityContext.Capture(ExecutionContext currThreadEC, StackCrawlMark& stackMark)
           at System.Threading.ExecutionContext.Capture(StackCrawlMark& stackMark, CaptureOptions options)
           at System.Threading.TimerBase.AddTimer(TimerCallback callback, Object state, UInt32 dueTime, UInt32 period, StackCrawlMark& stackMark)
           at System.Threading.Timer..ctor(TimerCallback callback, Object state, Int32 dueTime, Int32 period)
           at System.Runtime.Remoting.Lifetime.LeaseManager..ctor(TimeSpan pollTime)
           at System.Runtime.Remoting.Lifetime.LeaseManager.GetLeaseManager(TimeSpan pollTime)
           at System.Runtime.Remoting.Lifetime.LifetimeServices.GetLeaseInitial(MarshalByRefObject obj)
           at System.MarshalByRefObject.InitializeLifetimeService()
           at System.Runtime.Remoting.Lifetime.LeaseLifeTimeServiceProperty.GetObjectSink(MarshalByRefObject obj, IMessageSink nextSink)
           at System.Runtime.Remoting.Contexts.Context.CreateServerObjectChain(MarshalByRefObject serverObj)
           at System.Runtime.Remoting.ServerIdentity.GetServerObjectChain(MarshalByRefObject& obj)
           at System.Runtime.Remoting.RemotingServices.MarshalInternal(MarshalByRefObject Obj, String ObjURI, Type RequestedType, Boolean updateChannelData)
           at System.Runtime.Serialization.ObjectCloneHelper.GetObjectData(Object serObj, String& typeName, String& assemName, String[]& fieldNames, Object[]& fieldValues)
           at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
           at TESTGUI.Window1.LoadPlugins(String filename) in E:\Develop\TESTGUI\TESTGUI\Window1.xaml.cs:line 115
           at TESTGUI.Window1.button1_Click(Object sender, RoutedEventArgs e) in E:\Develop\TESTGUI\TESTGUI\Window1.xaml.cs:line 137
           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.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, WindowMessage 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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Boolean isSingleParameter, Delegate catchHandler)
           at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
           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.Application.RunDispatcher(Object ignore)
           at System.Windows.Application.RunInternal(Window window)
           at System.Windows.Application.Run(Window window)
           at System.Windows.Application.Run()
           at TESTGUI.App.Main() in E:\Develop\TESTGUI\TESTGUI\obj\x86\Debug\App.g.cs:line 0
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(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.Threading.ThreadHelper.ThreadStart()
      InnerException:



     ---- It works perfectly in .NET 3.5, but when changing to 4.0 this line breakes :(
    • Edited by _patrick_ Thursday, October 1, 2009 6:09 PM cleanup
    Thursday, October 1, 2009 6:05 PM

Answers

  • Hi,
    The exception occurs because type 'MS.Internal.Permissions.UserInitiatedRoutedEventPermission' is not mark with Serialiable attribute.
    This is a product issue, according to product team's response, it has been fixed internally, and you will see the change in the coming packages.

    Thanks,
    Eric


    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    • Marked as answer by eryang Friday, October 9, 2009 2:01 AM
    Wednesday, October 7, 2009 3:53 AM