web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

[DotNet variable] StreamContent, probem with serialization

(0) ShareShare
ReportReport
Posted on by 217

[Used variables]

StreamContent => System.Net.Http.StreamContent

File = > System.IO.File

FileMode => System.IO.FileMode

Hi,

I'm attempting to post a file on a web API.

I try to send the file into a streamcontent like this:

StreamContent := StreamContent.StreamContent(File.Open('PathToMyFile.tar.gz'), FileMode.Open));


Compilation is ok.
When I run the program, NAV says that the server instance is not available anymore. And the event log says that:

Type: System.Runtime.Serialization.SerializationException
Message: <ii>Type 'System.IO.FileStream' with data contract name 'FileStream:schemas.datacontract.org/.../System.IO'
is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known
statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list
of known types passed to the serializer.</ii>


To do that I'm working with documentation or questions asked about DotNet classes, which I translate to NAV and I think
I'm missing something in the using of StreamContent Class.

Here is an example given on StackOverflow which puts me in this way.

Thanks for your help !



*This post is locked for comments

I have the same question (0)
  • Hannes Holst Profile Picture
    5,767 on at

    Hi,

    Shouldn't it be like this?

    StreamContent := StreamContent.StreamContent(File.Open('PathToMyFile.tar.gz', FileMode.Open));


  • jdecottignies Profile Picture
    217 on at
    Hi,
    
    Shouldn't it be like this?
    
    StreamContent := StreamContent.StreamContent(File.Open('PathToMyFile.tar.gz', FileMode.Open));


    Thanks ! That was it ! :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans