By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,384 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Problem with Remoting..

P: n/a
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

=================
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

"Simon Verona" wrote:
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

=================

Nov 21 '05 #2

P: n/a
I'll check that out... the file that it is trying to write doesn't exist....

Regards
Simon
"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
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

"Simon Verona" wrote:
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

=================

Nov 21 '05 #3

P: n/a
Aha. So, you should use the permissions to create & write to the file then.

You never mentioned the file never existed, did you?

"Simon Verona" wrote:
I'll check that out... the file that it is trying to write doesn't exist....

Regards
Simon
"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
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

"Simon Verona" wrote:
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

=================


Nov 21 '05 #4

P: n/a
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.../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/Conte...x?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
"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:AD**********************************@microsof t.com...
Aha. So, you should use the permissions to create & write to the file
then.

You never mentioned the file never existed, did you?

"Simon Verona" wrote:
I'll check that out... the file that it is trying to write doesn't
exist....

Regards
Simon
"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
> 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
>
>
>
> "Simon Verona" wrote:
>
>> 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
>>
>>
>>
>> =================
>>
>>
>>


Nov 21 '05 #5

P: n/a
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?

"Simon Verona" wrote:
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.../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/Conte...x?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
"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:AD**********************************@microsof t.com...
Aha. So, you should use the permissions to create & write to the file
then.

You never mentioned the file never existed, did you?

"Simon Verona" wrote:
I'll check that out... the file that it is trying to write doesn't
exist....

Regards
Simon
"Crouchie1998" <Cr**********@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
> 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
>
>
>
> "Simon Verona" wrote:
>
>> 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
>>
>>
>>
>> =================
>>
>>
>>


Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.