0

I'm trying to upload a wave file thank's to FileStream, to a remoting server. Every time I try to use the function below, with my remoting interface:

public static void addAudioFile(FileStream source) { string fileName = source.Name.Split('\\').Last(); using (FileStream file = new FileStream(audioFolder + "\\" + fileName, FileMode.Create, System.IO.FileAccess.Write)) { byte[] bytes = new byte[source.Length]; source.Read(bytes, 0, (int)source.Length); file.Write(bytes, 0, bytes.Length); source.Close(); } } } 

I'm getting this error :

L'exception System.Security.SecurityException n'a pas été gérée HResult=-2146233078 Message=Le type System.Runtime.Remoting.ObjRef et les types qui en dérivent (tel que System.Runtime.Remoting.ObjRef) ne peuvent pas être désérialisés avec ce niveau de sécurité. Source=mscorlib StackTrace: Server stack trace: à System.Runtime.Serialization.FormatterServices.CheckTypeSecurity(Type t, TypeFilterLevel securityLevel) à System.Runtime.Serialization.Formatters.Binary.ObjectReader.CheckSecurity(ParseRecord pr) à System.Runtime.Serialization.Formatters.Binary.ObjectReader.ParseObject(ParseRecord pr) à System.Runtime.Serialization.Formatters.Binary.ObjectReader.Parse(ParseRecord pr) à System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record) à System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum) à System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run() à System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) à System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) à System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.UnsafeDeserialize(Stream serializationStream, HeaderHandler handler) à System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryRequestMessage(String objectUri, Stream inputStream, Boolean bStrictBinding, TypeFilterLevel securityLevel) à System.Runtime.Remoting.Channels.BinaryServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, IMessage requestMsg, ITransportHeaders requestHeaders, Stream requestStream, IMessage& responseMsg, ITransportHeaders& responseHeaders, Stream& responseStream) Exception rethrown at [0]: à System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) à System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) à ProjetZenAutomateClient.RemoteInterfaces.IRemoteZenAutomate.addAudioFile(FileStream source) à ProjetZenAutomateClient.iZenAutomate.addAudioFile(FileStream source) dans c:\TFVC-Geoffrey\Zen-Geoffreyg\Zen-Projets\GestionAutomate\Client\ProjetZenAutomateClient\iZenAutomate.cs:ligne 107 à ProjetZenAutomateWPF.ZenProjetEnvironnement.EventSelectionAddAudio(Object sender, RoutedEventArgs e) dans c:\TFVC-Geoffrey\Zen-Geoffreyg\Zen-Projets\GestionAutomate\Client\ProjetZenAutomateWPF\ZenProjetEnvironnement.cs:ligne 329 à System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) à System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) à System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) à System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) à System.Windows.Controls.Primitives.ButtonBase.OnClick() à System.Windows.Controls.Button.OnClick() à Microsoft.Windows.Controls.Ribbon.RibbonButton.OnClick() à System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) à System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) à System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) à System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) à System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) à System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) à System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) à System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e) à System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) à System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) à System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) à System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) à System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) à System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) à System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) à System.Windows.Input.InputManager.ProcessStagingArea() à System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) à System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) à System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) à System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) à System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) à MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) à MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) à System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) à MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) à System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) à MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) à MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) à System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) à System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) à System.Windows.Threading.Dispatcher.Run() à System.Windows.Application.RunDispatcher(Object ignore) à System.Windows.Application.RunInternal(Window window) à System.Windows.Application.Run(Window window) à System.Windows.Application.Run() à Zen.App.Main() dans c:\TFVC-Geoffrey\Zen-Geoffreyg\Zen-Common\Zen\obj\Debug\App.g.cs:ligne 0 à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() à System.Threading.ThreadHelper.ThreadStart_Context(Object state) à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) à System.Threading.ThreadHelper.ThreadStart() InnerException: 

I'm able to retrieve a file with filestream, but not to upload any file.

My client side call:

Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".wav"; dlg.Filter = "WAVE Files (*.wav)|*.wav"; Nullable<bool> result; result = dlg.ShowDialog(); if (result == true) { FileStream fs = File.Open(dlg.FileName, FileMode.Open); iAuto.addAudioFile(fs); } 

iAuto.addAudioFile(fs) being the call of my interface method

1

1 Answer 1

0

Found a solution.

I converted my file to a byte array:

byte[] byteFile = File.ReadAllBytes(dlg.FileName); 

Thank's to that, I was able to send the data on my server side application, and then I used the code below o convert it back to a file on my server

File.WriteAllBytes(audioFolder + "\\" + fileName, file); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.