Problem with Remoting..

S

Simon Verona

I have a pair of functions that I'm calling using remoting - called readfile
and writefile.

The readfile works fine when called from the client PC.

The writefile method returns an error:

"Because of security restrictions, the type System.Runtime.Remoting.ObjRef
cannot be accessed".

I'm guessing this is some sort of security restriction preventing writes to
the filesystem by remoting???

My code is as below.... Hope somebody can help.. If I put the server code
"inline" instead of using remoting it works fine.

Regards
Simon

Client Code :

Dim fstream As System.IO.FileStream =
System.IO.File.Open(OpenFileDialog1.FileName, IO.FileMode.OpenOrCreate)

Dim mstream As New System.IO.MemoryStream

Dim dat(fstream.Length - 1) As Byte

fstream.Read(dat, 0, fstream.Length)

mstream.Write(dat, 0, fstream.Length)

fstream.Close()

dms.WriteFile("d:\dms\webs\images\" & CInt(_StockNo) & ".jpg", mstream)

mstream.Close()

-----------------------------------------------------

Server Code (called by remoting).



Public Sub WriteFile(ByVal filename As String, ByVal Dat As
System.IO.MemoryStream)

' write a file

Try

Dim file As System.IO.File

Dim stream As System.IO.FileStream = file.Open(filename,
FileMode.OpenOrCreate)

stream.Write(Dat.GetBuffer, 0, Dat.Length)

stream.Close()

Catch

End Try

End Sub



=================
 
G

Guest

Lookup 'FileIOPermissions' because I think you need to set the write
permission to that file

Set the permission

Assert the permission

Do file handling here

RevertAssert

fp (file permissions) = nothing
 
S

Simon Verona

I'll check that out... the file that it is trying to write doesn't exist....

Regards
Simon
 
G

Guest

Aha. So, you should use the permissions to create & write to the file then.

You never mentioned the file never existed, did you?
 
S

Simon Verona

Ok, just in case anybody else sees this thread with the same problem.

The problem has nothing to do with file permissions, nor whether the file
actually exists at all.

It's to do with the way the .Net framework handles and serializes streams in
v1.1 of the Framework.

For further details please see
http://blogs.msdn.com/sanpil/archive/2004/02/23/78754.aspx

This works for smallish files <320kb..... Apparently, above this level the
Framework serializes the files using a different methodology which is much
less efficient. For a better solution on larger files see
http://www.genuinechannels.com/Content.aspx?id=23&type=1.

The solution I used was to change my memorystream for a bytearray... This is
much faster in any case :)

(acknowledgements to Ken Kolda in microsoft.public.dotnet.remoting
newsgroup who gave me the pointers and the answers)

Regards
Simon
 
G

Guest

Download the .NET Framework SDK & look it up yourself.

In your original post you said its to do with security. Therefore, if you
use code access security to read/write your file it should solve the issue.

Your second post tells me that the file doesn't exist, which is now
different from your original post.

Use a Try-Catch-End Try block around the code that is erroring & use
MessageBox.Show(ex.ToString()) to get the full error. Then post pack your
findings

All I am trying to do is help you, but if you keep changing your mind as to
what the problem is then its not that easy to solve, is it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top