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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans