Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have gotten a tremendous amount of information from the question posted at (Load a Mathematica Package via .Net code), which my application is very similar to. Specifically in that thread, the author uses:

MathKernel k = new MathKernel();  //Establishes a Mathematica kernel  
k.Compute("<< XYZ`XYZGraphs`");   //Runs an entire package file   
string res = k.Result.ToString(); //Collects the result of the file

I was wondering if there was a similar process for a Notebook file? When I tried referencing a Notebook file in the same manner, the math kernel returns $Failed as the result.

Other solutions I thought might work but have not had any success with have been using IKernelLink and IMathLink, or converting the Notebook file to a Package file. I also saw a thread about running from the command line but I am not sure how I would get the results of the Notebook back into .Net using that method.

I would greatly appreciated any advice, thanks!

share|improve this question
Notebooks contain a lot of content which doesn't mean anything to the Kernel, they're loaded by the FrontEnd. This is the process you can see running called Mathematica rather than MathKernel when you run Mathematica directly. In interactive operation the frontend sends expressions to the kernel from a notebook. – Ymareth Jan 30 '14 at 16:40
As Ymareth said, notebooks are not made for this purpose and you should not try to use them this way. You were on the right track when you were thinking of converting the notebook to a package (i.e. plain text file with .m extension and Mathematica commands within). How to do that is explained here. – Szabolcs Jan 30 '14 at 16:50
@Szabolcs That is exactly the type of information I needed to move forward. Thank you! – Josh Jan 30 '14 at 17:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.