Skip to main content

Notifications

Microsoft Dynamics NAV (Archived)

[DotNet variable] StreamContent, probem with serialization

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

  • jdecottignies Profile Picture
    jdecottignies 217 on at
    RE: [DotNet variable] StreamContent, probem with serialization
    Hi,
    
    Shouldn't it be like this?
    
    StreamContent := StreamContent.StreamContent(File.Open('PathToMyFile.tar.gz', FileMode.Open));


    Thanks ! That was it ! :)

  • Hannes Holst Profile Picture
    Hannes Holst 5,767 on at
    RE: [DotNet variable] StreamContent, probem with serialization

    Hi,

    Shouldn't it be like this?

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


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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans