Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send mail with attachment file #403

Open
ngoctuan opened this issue Jul 21, 2015 · 4 comments
Open

Send mail with attachment file #403

ngoctuan opened this issue Jul 21, 2015 · 4 comments

Comments

@ngoctuan
Copy link

Hello,

I use Hangfire for send background email, but have error when mail has attachment file.

My bug as bellow, pls help to fix

message: "Newtonsoft.Json.JsonSerializationException: Error getting value from 'ReadTimeout' on 'System.IO.MemoryStream'. ---> System.InvalidOperationException: Timeouts are not supported on this stream.
↵ at System.IO.Stream.get_ReadTimeout()
↵ at GetReadTimeout(Object )
↵ at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)
↵ --- End of inner exception stack trace ---
↵ at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)
↵ at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)
↵ at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
↵ at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
↵ at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
↵ at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
↵ at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
↵ at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
↵ at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
↵ at Astro.Hangfire.Common.JobHelper.ToJson(Object value) in

@IanYates
Copy link

I'd say you're serializing the stream for your attachments... Try passing them as a byte array instead or pass some identifier which will let your Hangfire job retrieve the attachments from more permanent storage. When JSON.Net is deserializing your stream it's trying to set properties that can't be set such as "ReadTimeout".

@ngoctuan
Copy link
Author

Many thanks, I will test and feedback soon

@odinserj
Copy link
Member

Please don't pass big argument values to Hangfire, keep them as simple as possible. Instead, save your attachments to your storage first and pass their identifiers to background job method.

@darjanbogdan
Copy link

darjanbogdan commented Dec 9, 2016

I can confirm that byte array instead of Stream works, thank you @IanYates!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants