MimeKit .Net Core : The target process exited with code -1073741819 while evaluating the function "MimeKit.MimeMessage.ToString" - mailkit

I am using Mimekit/Mailkit to forward mail in my .Net core app.
The system exits with the following error :
The target process exited with code -1073741819 while evaluating the function "MimeKit.MimeMessage.ToString"
While executing these lines:
var builder = new BodyBuilder();
builder.TextBody = forwardMail.Body ?? string.Empty;
builder.Attachments.Add(new MessagePart { Message = message });
message.Body = builder.ToMessageBody();
It is happening all the time. Why is this? How can I fix this issue ?

You are making the message recursive.
message.Body = something that embeds message
When you call ToString() on it, the message gets written first to a MemoryStream (and from there, gets converted into a string) and the MemoryStream buffer must continue growing without bounds because there is no end to a recursive message.
You likely meant to embed a different message, but your code has a body part of the message pointing back to the top-level message again resulting in an infinite loop when it gets written out.

Related

DataStage calling user-defined server routine in job batch

Currently, I want to send a mail with log information inside a job batch whenever it got aborted status. My notification activity works fine but I just want to try to send it via job batch code.
I have created a server routine in DataStage which will send mail based on the job name passed through the job batch.
Below is my code for the server routine test.
$INCLUDE DSINCLUDE JOBCONTROL.H
MailArg<-1> = "From: sender#gmail.com"
MailArg<-1> = "To: receiver#gmail.com"
MailArg<-1> = "Subject: Test"
MailArg<-1> = "Body: Job " : Input : " aborted."
mail = DSSendMail(MailArg)
ErrorCode = 0 ;* set this to non-zero to stop the stage/job
When I check this server routine with DSRoutineChecker, the email sent successfully. Then I do some searching and people say that I can call my own defined routine with DEFFUN in job batch code.
But it didn't work for me.
Below is the code in the job batch.
* Setup job_2, run it, wait for it to finish, and test for success
hJob1 = DSAttachJob("job_2", DSJ.ERRFATAL)
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed: job_2", "JobControl")
Abort
End
ErrCode = DSSetDisableProjectHandler(hJob1, #FALSE)
ErrCode = DSSetDisableJobHandler(hJob1, #FALSE)
Call DSSetJobQueue(ErrCode, hJob1, "MediumPriorityJobs")
ErrCode = DSRunJob(hJob1, DSJ.RUNNORMAL)
ErrCode = DSWaitForJob(hJob1)
Status = DSGetJobInfo(hJob1, DSJ.JOBSTATUS)
If Status = DSJS.RUNFAILED Or Status = DSJS.CRASHED Then
* Fatal Error - No Return
DEFFUN test("JOB_2") CALLING "DSU.test"
Call DSLogFatal("Job Failed: job_2", "JobControl")
End
All lines are auto-generated when added the job job_2 except the DEFFUN line at the end. If I replaced the server routine code with the DEFFUN line and sending mail directly, it'd work too.
But I want to call one line each time per job added if there's a lot of jobs, so I go with the server routine for not having to copy/ paste the MailArg paragraph for each job code.
It seems to me that the calling line is having some trouble. Do you guys have any idea how I can do it?
DEFFUN is a compiler declaration, and should appear before any executable statement. It is simply setting up the calling name and argument list for the actual function. For example
DEFFUN test(Arg1) Calling "DSU.test"
Somewhere you need to call your "test" function. For example
ErrCode = test("JOB_2")
If the mail arguments are never going to change, you could leave them in your routine.
Otherwise you can pass them all as a delimited string, or as separate arguments. If you rewrite test to have more than one argument, then the DEFFUN declaration will need to be refined to include the correct number of arguments, and the actual call will have to be provided with that many values for those arguments.

Can't process quickfix messages written in file

In my C++ QuickFix application, I am recording all MarketDataIncrementalRefresh messages i am getting into a file. This is being done using the following code:
void Application::onMessage(const FIX44::MarketDataIncrementalRefresh& message, const FIX::SessionID&)
{
ofstream myfile("tapedol.txt", std::ios::app);
myfile << message << endl << endl;
}
This part's working just fine. The problem occurs when I try to load the message later on.
FIX::Message msg
ifstream myfile("tapedol.txt");
getline(myfile,aux);
msg = aux;
msg.getField(55);
The program crashes every time it executes the last line. I suspect the problem is at the assignment to msg, but i'm not sure. If it is, what is the correct way to do such assignment? If not, how can I process the data within tapedol.txt, so that a message of type MarketDataIncremental refresh would be generated for each string in the file?
Your question is not complete enough to provide a full answer, but I do see one red flag:
msg.getField(55);
The Symbol field is not a top-level field of MarketDataIncrementalRefresh (it's inside the NoMDEntries repeating group), so this line will fail. I think it would raise a FieldNotFound exception.
My C++ is rusty, but you should be able to catch an exception or something that should tell you exactly what line is erroring out. Barring that, you need to open up a debugger. Just saying "it crashed" means you quit looking too soon.

With Tibco Rendezvous, how catch errors that are being printed to the console?

In Tibco, sometimes warnings are printed to the console, e.g.:
2014-06-25 18:13:22 RV: TIB/Rendezvous Error Not Handled by Process:
{ADV_CLASS="WARN" ADV_SOURCE="RVCM"
ADV_NAME="REGISTRATION.NOT_CERTIFIED.cm.test.subject"
subject="cm.test.subject" sender="cm.sender.cmname"}
I am using the .NET wrappers for Tibco. It appears as if these errors are not actually making it into the .NET, and they can't be caught with try/catch so they can be handled appropriately.
Is there any way to handle this error in .NET? Perhaps some method of registering a handler to handle errors such as this? Or alternatively, is there a method to redirect these warnings into a sink other than the console, e.g. a log file?
The solution is to add a "catch all" handler.
The current subject that I was listening to was:
private readonly string _subjectDeliveryConfirm = "_RV.INFO.RVCM.DELIVERY.CONFIRM.>";
To add a catch all, add another listener on:
private readonly string _subjectDeliveryGlobal = ">";
When you add a new listener, remember to use a separate Listener concrete class per listener, or else Tibco will mysteriously stop working after the first message (see the demo code for how to create multiple listeners).
_confirmListener1 = new Listener(Queue.Default, _netTransport, _subjectDeliveryConfirm, null);
_confirmListener1.MessageReceived += new MessageReceivedEventHandler(OnCertifiedMessageConfirmed);
// Subscribe to error messages, in particular error messages related to remote listener processes
// disappearing.
_confirmListener2 = new Listener(Queue.Default, _netTransport, _subjectDeliveryGlobal, null);
_confirmListener2.MessageReceived += new MessageReceivedEventHandler(OnTibcoCatchAll);
There is lots of sample C# code in the \src\ directory for the Tibco install that illustrates the techniques shown above.

SWFUpload + jQuery.SWFUpload - Remove File From Queue

I'm facing a big issue IMO.
First, here's my code:
.bind('uploadSuccess', function(event, file, serverData){
if(serverData === 'nofile') {
var swfu = $.swfupload.getInstance('#form');
swfu.cancelUpload(file.id); // This part is not working :(
} else {
alert('File uploaded');
}
})
In this part I'm checking server response (I'm have strict validation restrictions). Now my question. Is it possible to remove uploaded file from queue? Basically, if server returns error I display error message, but... this file still exsit in the queue (I've implemented checking filename and filesize to avoid duplicated uploads) and user is not possible to replace this file (due to upload and queue limit).
I was trying to search for a solution, but without success. Any ideas?
Regards,
Tom
From the link
http://swfupload.org/forum/generaldiscussion/881
"The cancelUpload(file_id) function
allows you to cancel any file you have
queued.
You just have to keep the file's ID
value so you can pass it to
cancelUpload when you call it."
Probably you have to keep the file ID before sending anything to the server

MessageReadPropertyFilter getting reset when using MSMQ

Strange one. We have a multi-threaded app which pulls messages off a MSMQ Queue and then subsequently performs actions based on the messages. All of this is done using DTC.
Sometimes, for some reason I can't describe, we get message read errors when pulling Messages off the queue.
The code that is being used in the app:
Message[] allMessagesOnQueue = this.messageQueue.GetAllMessages();
foreach (Message currentMessage in allMessagesOnQueue)
{
if ((currentMessage.Body is IAMessageIDealWith))
{
// do something;
}
}
When the currentMessage.Body is accessed, at times it throws an exception:
System.InvalidOperationException: Property Body was not retrieved when receiving the message. Ensure that the PropertyFilter is set correctly.
Now - this only happens some of the time - and it appears as though the MessageReadPropertyFilter on the queue has the Body property set to false.
As to how it gets like this is a bit of a mystery. The Body property is one of the defaults and we absolutley never explicitly set it to false.
Has anyone else seen this kind of behaivour or has some idea why this value is getting set to be false?
As alluded to earlier, you could explicitly set the boolean values on the System.Messaging.MessagePropertyFilter object that is accessible on your messageQueue object via the MessageReadPropertyFilter property.
If you want all data to be extracted from a message when received or peaked, use:
this.messageQueue.MessageReadPropertyFilter.SetAll(); // add this line
Message[] allMessagesOnQueue = this.messageQueue.GetAllMessages();
// ...
That may hurt performance of reading many messages, so if you want just a few additional properties, create a new MessagePropertyFilter with custom flags:
// Specify to retrieve selected properties.
MessagePropertyFilter filter= new MessagePropertyFilter();
filter.ClearAll();
filter.Body = true;
filter.Priority = true;
this.messageQueue.MessageReadPropertyFilter = filter;
Message[] allMessagesOnQueue = this.messageQueue.GetAllMessages();
// ...
You can also set it back to default using:
this.messageQueue.MessageReadPropertyFilter.SetDefaults();
More info here: http://msdn.microsoft.com/en-us/library/system.messaging.messagequeue.messagereadpropertyfilter.aspx
I have seen it as well, and have tried initializing it with the properties I'm accessing explicitly set, and not setting them anywhere else. I periodically get the same error you are getting, my app is multi-threaded as well, what I ended up doing is trapping that error and reconnecting to MSMQ when I get it.
Sometimes, for some reason I can't describe, we get message read errors when pulling Messages off the queue.
Are you using the same MessageQueue instance from more than one thread, without locking? In that case, you will encounter spurious changes in MessageReadPropertyFilter - at least I did, when I tried.
Why? Because
Only the GetAllMessages method is thread safe.
What can you do? Either
wrap a lock (_messageQueue) around all access to your messageQueue OR
create multiple MessageQueue instances, one per thread