System.Collections.Generic.KeyNotFoundException: The given key ‘00000000-0000-0000-0000-000000000000, 0’ was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at .()
at .()
at .()
at .(Stream )
at .(Stream )
at .(Stream , String )
at tream , String , Boolean )
at .(Stream , Document , LoadOptions )
at Aspose.Note.Document.(Stream , LoadOptions )
at Aspose.Note.Document…ctor(Stream inStream, LoadOptions loadOptions)
at Aspose.Note.Document…ctor(Stream inStream)
I’m getting this exception while converting onenote document to pdf on the below code, please resolve this issue:
public List TransformOneNoteFileToPdfStream(byte[] documentBytes)
{
var pdfContent = new MemoryStream();
var license = new License();
license.SetLicense(“Aspose.Note.NET.lic”);
var document = new Document(new MemoryStream(documentBytes));
var pdfDocuments = new List();
IList pages = document.GetChildNodes();
for (int i = 0; i < pages.Count(); i++)
{
PdfSaveOptions opts = new PdfSaveOptions();
opts.PageIndex = i;
opts.PageCount = 1;
document.Save(pdfContent, opts);
pdfDocuments.Add(new OneNoteConvertedFileDto
{
PageTitle = pages[i].Title?.TitleText.Text,
File = pdfContent,
PageIndex = i + 1
});
pdfContent = new MemoryStream();
}
return pdfDocuments.Count() > 0 ? pdfDocuments : null;
}
I have attached onenote file for your reference:
response.zip (70.2 KB)
@pdhakal
The KeyNotFoundException
you are encountering while converting a OneNote document to PDF using Aspose.Note may be related to a specific issue with the library when handling certain OneNote files. This has been reported by other users as well, and it appears that the issue has been acknowledged by the Aspose team.
Here are some steps you can take to troubleshoot and potentially resolve the issue:
-
Check for Updates: Ensure that you are using the latest version of Aspose.Note. The issue you are facing may have been fixed in a more recent release. You can check the release notes for updates here.
-
File Compatibility: The exception may occur due to the specific OneNote file you are trying to convert. If possible, test with different OneNote files to see if the issue persists across all files or is isolated to a specific document.
-
Error Handling: Implement error handling in your code to catch exceptions and log additional information. This can help you identify if the issue is with the document itself or the conversion process.
-
Contact Support: If the problem continues, consider reaching out to Aspose support for further assistance. They may provide insights or workarounds specific to your case.
Here is a simplified version of your code with added error handling:
public List<OneNoteConvertedFileDto> TransformOneNoteFileToPdfStream(byte[] documentBytes)
{
var pdfDocuments = new List<OneNoteConvertedFileDto>();
try
{
using (var pdfContent = new MemoryStream())
{
var license = new License();
license.SetLicense("Aspose.Note.NET.lic");
var document = new Document(new MemoryStream(documentBytes));
IList<Page> pages = document.GetChildNodes<Page>();
for (int i = 0; i < pages.Count; i++)
{
PdfSaveOptions opts = new PdfSaveOptions
{
PageIndex = i,
PageCount = 1
};
document.Save(pdfContent, opts);
pdfDocuments.Add(new OneNoteConvertedFileDto
{
PageTitle = pages[i].Title?.TitleText.Text,
File = new MemoryStream(pdfContent.ToArray()), // Create a new MemoryStream for each page
PageIndex = i + 1
});
pdfContent.SetLength(0); // Clear the MemoryStream for the next page
}
}
}
catch (Exception ex)
{
// Log the exception or handle it as needed
Console.WriteLine($"An error occurred: {ex.Message}");
}
return pdfDocuments.Count > 0 ? pdfDocuments : null;
}
This code includes error handling and ensures that a new MemoryStream
is created for each page to avoid issues with overlapping data.
If you continue to experience the KeyNotFoundException
, it may be beneficial to provide the specific OneNote file to Aspose support for further investigation.
Sources:
[1]: KeyNotFoundException when loading the file
response.zip (70.2 KB)
please take this file as a reference for the above issue
@pdhakal,
Which version of Aspose.Note for .NET you are using. Please try using Aspose.Note for .NET 24.9. I have tested using the following line of code with Aspose.Note for .NET 24.9 and it works fine.
e.g.,
var document = new Document("e:\\test2\\response.one");
Let us know with details if you still find the issue.
@amjad.sahi
hi , I m facing new error while converting onenote document to pdf and also i have use latest version of aspose (25.2.0) here is the error:
System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.First[TSource](IEnumerable1 source) at e.e(Color , Single , IEnumerable
1 )
at e.(InkNode )
at e.VisitInkWordStart(InkWord )
at Aspose.Note.InkWord.Accept(DocumentVisitor visitor)
at Aspose.Note.CompositeNode1.Accept(DocumentVisitor visitor) at Aspose.Note.OutlineElement.Accept(DocumentVisitor visitor) at Aspose.Note.CompositeNode
1.Accept(DocumentVisitor visitor)
at Aspose.Note.Outline.Accept(DocumentVisitor visitor)
at Aspose.Note.CompositeNode1.Accept(DocumentVisitor visitor) at .(Page ) at .(IList
1 )
at .(Document , )
at .()
at .(Document , Stream , SaveOptions )
at Aspose.Note.Document.Save(Stream stream, SaveOptions options)
@pdhakal,
Thank you for providing the details.
I tested your scenario/case using the sample document “Network Overview.one” (which you initially shared via Google Drive in the thread before editing the post to remove the link). Everything works as expected, and I did not encounter any errors. Additionally, the output PDF file is properly rendered. I utilized the following sample code for testing using your sample document with Aspose.Note for .NET v25.2:
var document = new Aspose.Note.Document("e:\\test2\\Network Overview.one");
document.Save("e:\\test2\\out1.pdf");
Are you using a different file? If yes, please share the document with us so we can test and evaluate the issue on our end. Once confirmed, we will log the appropriate ticket in our database to ensure it gets resolved promptly.
in my code my get error while processing page Title called “New User Setup Guide” so can you please give some ideas on this i have attached the code here:
public List<OneNoteConvertedFileDto> TransformOneNoteFileToPdfStream(byte[] documentBytes)
{
var pdfContent = new MemoryStream();
var license = new License();
license.SetLicense("Aspose.Note.NET.lic");
var document = new Document(new MemoryStream(documentBytes));
var pdfDocuments = new List<OneNoteConvertedFileDto>();
IList<Page> pages = document.GetChildNodes<Page>();
for (int i = 0; i < pages.Count(); i++)
{
PdfSaveOptions opts = new PdfSaveOptions();
opts.PageIndex = i;
opts.PageCount = 1;
document.Save(pdfContent, opts);
pdfDocuments.Add(new OneNoteConvertedFileDto
{
PageTitle = pages[i].Title?.TitleText.Text,
File = pdfContent,
PageIndex = i + 1
});
pdfContent = new MemoryStream();
}
return pdfDocuments.Count() > 0 ? pdfDocuments : null;
}
This the Dto used
public class OneNoteConvertedFileDto
{
public string PageTitle { get; set; }
public int PageIndex { get; set; }
public MemoryStream File { get; set; }
}
@pdhakal,
Do you use “Network Overview.one” document (you previously shared via a download link, which was later removed by you) in your code? The provided code snippet might not be processed precisely due to certain objects and attributes that remain unclear. It looks like you are using Aspose.Note API with Aspose.PDF API in code. We would greatly appreciate it if you could share a standalone sample console application, including the complete source code free of compilation errors, to help us reproduce the issue on our end. Please zip the project along with necessary resource files and either attach it here or upload it to Google Drive. We will check your issue soon.
Sorry I can’t provide you the whole project but, I can give the ideas on how this code is implemented on our application:
this above function is expecting the byte data directly download from the sharepoint API and convert it into the pdf by processing each page one by one into pdf page. so, for the demo purpose you can upload the file i have provided “Network OverView.one” on the sharepoint and try to download same document viva code (you can write own code to download document from sharepoint api) and try to pass same download byte into the function i have provided so you get an idea on the error i m facing,
Note: I m using dotnet for coding
@pdhakal,
Thanks for providing further details.
It would be hard to evaluate your issue as you have not provided the whole project. Anyways, we will try to look into your issue. We require thorough evaluation and investigation of your issue, so kindly spare us sometime. We have opened the following new investigation ticket in our internal issue tracking system.
Issue ID(s): NOTENET-5871
Once we have an update on it, we will let you know here.
@pdhakal,
We are pleased to inform you that we have successfully reproduced the issue and identified the root cause. The fix is scheduled to be included in the upcoming release of Aspose.Note 25.4, planned for next month.