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

SoapFormatter only works in Full Trust?

P: n/a
Hi there.

I posted an earlier issue under the name "That assembly does not allow
partially trusted callers" but have now identified what the issue is.

As explained before I am working in ASP.Net 2.0 using VB.Net and had
developed an application that ran correctly on my development server but
would not run on the shared hosting paltform which I use. The shared hosting
runs in medium trust and produced the error "That assembly does not allow
partially trusted callers"

Having played around a fair bit I have now (I think) narrowed this down to
the SoapFormatter class which I use to serialize and desiralize a class.

Code as follows:

Private Sub SerializeClass(ByVal _exRate As exRate, ByVal Path As String)

Try
Dim sf As New SoapFormatter
Dim fs As New FileStream(Path, FileMode.Create)

sf.Serialize(fs, _exRate)
fs.Close()

Catch ex As Exception
Dim myNotification As New Notification
myNotification.Subject = "Serialization Failed"
myNotification.Message = "Serialization Failed" & ex.ToString
myNotification.SendNotification(myNotification)
End Try

End Sub

and

Private Function DeserializeClass(ByVal Path As String) As exRate

Dim myExRate As New exRate

Try
Dim fs As New FileStream(Path, FileMode.Open)
Dim sf As New SoapFormatter

myExRate = CType(sf.Deserialize(fs), exRate)
fs.Close()
Catch ex As Exception
End Try

Return myExRate

End Function

I now understand that the SoapFormatter class only works in full trust. Is
there a work around for this issue or perhaps a better way to do the above.

I was basically trying to save the values for the properties of the class to
be used at a later date.
--
Regards

Martyn Fewtrell
mf*******@networkclub.co.uk

May 5 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I couldn't find where the soapformatter class requires full trust, granted I
didn't look long and hard either.

If that's the case, you will need to use CAS policy to remove that
restriction. Use the configuration utility to configure the appropriate
policy on the assembly. Ideally, you would grant the assembly full trust
(not recommended) or some combination of permissions to allow it run that is
less than full trust.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"Martyn Fewtrell" <mf*******@newsgroup.nospamwrote in message
news:B1**********************************@microsof t.com...
Hi there.

I posted an earlier issue under the name "That assembly does not allow
partially trusted callers" but have now identified what the issue is.

As explained before I am working in ASP.Net 2.0 using VB.Net and had
developed an application that ran correctly on my development server but
would not run on the shared hosting paltform which I use. The shared
hosting
runs in medium trust and produced the error "That assembly does not allow
partially trusted callers"

Having played around a fair bit I have now (I think) narrowed this down to
the SoapFormatter class which I use to serialize and desiralize a class.

Code as follows:

Private Sub SerializeClass(ByVal _exRate As exRate, ByVal Path As String)

Try
Dim sf As New SoapFormatter
Dim fs As New FileStream(Path, FileMode.Create)

sf.Serialize(fs, _exRate)
fs.Close()

Catch ex As Exception
Dim myNotification As New Notification
myNotification.Subject = "Serialization Failed"
myNotification.Message = "Serialization Failed" & ex.ToString
myNotification.SendNotification(myNotification)
End Try

End Sub

and

Private Function DeserializeClass(ByVal Path As String) As exRate

Dim myExRate As New exRate

Try
Dim fs As New FileStream(Path, FileMode.Open)
Dim sf As New SoapFormatter

myExRate = CType(sf.Deserialize(fs), exRate)
fs.Close()
Catch ex As Exception
End Try

Return myExRate

End Function

I now understand that the SoapFormatter class only works in full trust. Is
there a work around for this issue or perhaps a better way to do the
above.

I was basically trying to save the values for the properties of the class
to
be used at a later date.
--
Regards

Martyn Fewtrell
mf*******@networkclub.co.uk

May 6 '07 #2

P: n/a
Alvin

Thanks for your response.

If you look at the following MSDN article:

http://msdn2.microsoft.com/en-us/lib...hf(VS.80).aspx

There is a section at the bottom that seems to indicate that the serialise
method requires Full Trust.

--------------------------------------------------------------------
..NET Framework Security

Full trust for the immediate caller. This member cannot be used by partially
trusted code. For more information, see .

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

I assume where you are reffering to the CAS policy you are reffering to
editing the machine.config file and adding a line that basically says the
equivalent of grant SoapFormatter full trust but nothing else?

--
Regards

Martyn Fewtrell
"Alvin Bruney [MVP]" wrote:
I couldn't find where the soapformatter class requires full trust, granted I
didn't look long and hard either.

If that's the case, you will need to use CAS policy to remove that
restriction. Use the configuration utility to configure the appropriate
policy on the assembly. Ideally, you would grant the assembly full trust
(not recommended) or some combination of permissions to allow it run that is
less than full trust.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"Martyn Fewtrell" <mf*******@newsgroup.nospamwrote in message
news:B1**********************************@microsof t.com...
Hi there.

I posted an earlier issue under the name "That assembly does not allow
partially trusted callers" but have now identified what the issue is.

As explained before I am working in ASP.Net 2.0 using VB.Net and had
developed an application that ran correctly on my development server but
would not run on the shared hosting paltform which I use. The shared
hosting
runs in medium trust and produced the error "That assembly does not allow
partially trusted callers"

Having played around a fair bit I have now (I think) narrowed this down to
the SoapFormatter class which I use to serialize and desiralize a class.

Code as follows:

Private Sub SerializeClass(ByVal _exRate As exRate, ByVal Path As String)

Try
Dim sf As New SoapFormatter
Dim fs As New FileStream(Path, FileMode.Create)

sf.Serialize(fs, _exRate)
fs.Close()

Catch ex As Exception
Dim myNotification As New Notification
myNotification.Subject = "Serialization Failed"
myNotification.Message = "Serialization Failed" & ex.ToString
myNotification.SendNotification(myNotification)
End Try

End Sub

and

Private Function DeserializeClass(ByVal Path As String) As exRate

Dim myExRate As New exRate

Try
Dim fs As New FileStream(Path, FileMode.Open)
Dim sf As New SoapFormatter

myExRate = CType(sf.Deserialize(fs), exRate)
fs.Close()
Catch ex As Exception
End Try

Return myExRate

End Function

I now understand that the SoapFormatter class only works in full trust. Is
there a work around for this issue or perhaps a better way to do the
above.

I was basically trying to save the values for the properties of the class
to
be used at a later date.
--
Regards

Martyn Fewtrell
mf*******@networkclub.co.uk


May 7 '07 #3

P: n/a
Yes i was, its rather easy to create a cas policy and push it to the prod.
environment. That will fix you up.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"Martyn Fewtrell" <mf*******@newsgroup.nospamwrote in message
news:6A**********************************@microsof t.com...
Alvin

Thanks for your response.

If you look at the following MSDN article:

http://msdn2.microsoft.com/en-us/lib...hf(VS.80).aspx

There is a section at the bottom that seems to indicate that the serialise
method requires Full Trust.

--------------------------------------------------------------------
.NET Framework Security

Full trust for the immediate caller. This member cannot be used by
partially
trusted code. For more information, see .

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

I assume where you are reffering to the CAS policy you are reffering to
editing the machine.config file and adding a line that basically says the
equivalent of grant SoapFormatter full trust but nothing else?

--
Regards

Martyn Fewtrell
"Alvin Bruney [MVP]" wrote:
>I couldn't find where the soapformatter class requires full trust,
granted I
didn't look long and hard either.

If that's the case, you will need to use CAS policy to remove that
restriction. Use the configuration utility to configure the appropriate
policy on the assembly. Ideally, you would grant the assembly full trust
(not recommended) or some combination of permissions to allow it run that
is
less than full trust.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"Martyn Fewtrell" <mf*******@newsgroup.nospamwrote in message
news:B1**********************************@microso ft.com...
Hi there.

I posted an earlier issue under the name "That assembly does not allow
partially trusted callers" but have now identified what the issue is.

As explained before I am working in ASP.Net 2.0 using VB.Net and had
developed an application that ran correctly on my development server
but
would not run on the shared hosting paltform which I use. The shared
hosting
runs in medium trust and produced the error "That assembly does not
allow
partially trusted callers"

Having played around a fair bit I have now (I think) narrowed this down
to
the SoapFormatter class which I use to serialize and desiralize a
class.

Code as follows:

Private Sub SerializeClass(ByVal _exRate As exRate, ByVal Path As
String)

Try
Dim sf As New SoapFormatter
Dim fs As New FileStream(Path, FileMode.Create)

sf.Serialize(fs, _exRate)
fs.Close()

Catch ex As Exception
Dim myNotification As New Notification
myNotification.Subject = "Serialization Failed"
myNotification.Message = "Serialization Failed" &
ex.ToString
myNotification.SendNotification(myNotification)
End Try

End Sub

and

Private Function DeserializeClass(ByVal Path As String) As exRate

Dim myExRate As New exRate

Try
Dim fs As New FileStream(Path, FileMode.Open)
Dim sf As New SoapFormatter

myExRate = CType(sf.Deserialize(fs), exRate)
fs.Close()
Catch ex As Exception
End Try

Return myExRate

End Function

I now understand that the SoapFormatter class only works in full trust.
Is
there a work around for this issue or perhaps a better way to do the
above.

I was basically trying to save the values for the properties of the
class
to
be used at a later date.
--
Regards

Martyn Fewtrell
mf*******@networkclub.co.uk



May 7 '07 #4

P: n/a
Hi Martyn,

As you have already knew, the SoapFormatter.Serialize requires immediate
caller must have full trust. There're several approaches for such scenario,
please see following article for more information:

#How To: Use Code Access Security in ASP.NET 2.0
http://msdn2.microsoft.com/en-us/library/ms998326.aspx
For example, one possible approach is to create a wrapper assembly,
configure this wrapper assembly to run with full trust, and apply
AllowPartialTrustedCallersAttribute to this wrapper assembly; then you can
call this wrapper assembly from your web application.
Hope this helps. Please feel free to let me know if there's anything
unclear. Thanks.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

May 9 '07 #5

P: n/a
Hi Martyn,

Please feel free to let us know if the issue is still not resolved. Thanks.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

May 14 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.