473,396 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with Remoting..

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
5 1364
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Sudesh Sawant | last post by:
Hello, We have an application which communicates using remoting. There is a server which is a Windows Service. The server exposes an object which is a singleton. The client is a Web Application...
8
by: Sudesh Sawant | last post by:
Hello, We have an application which communicates using remoting. There is a server which is a Windows Service. The server exposes an object which is a singleton. The client is a Web Application...
0
by: Martijn Damen | last post by:
Hi, At the moment I am trying to develop an application that uses another app over .net remoting and having some problems with it (ok, that is ofcourse why I am here), hope somebody can shine a...
12
by: Sudesh Sawant | last post by:
Hello, We have an application which communicates using remoting. There is a server which is a Windows Service. The server exposes an object which is a singleton. The client is a Web Application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.