DotNet code in NAV - problems with overloads
Aquir
Member Posts: 23
Hi,
I'm trying to implement this code in NAV:
(a simple converter from RTF to HTML)
I'm stuck with this line:
the possible overloads:
not matter what I try I get this
"The function call was ambiguous. No matching method was found."
this is the C/AL code
any ideas?
I'm trying to implement this code in NAV:
(a simple converter from RTF to HTML)
using System;
using System.IO;
using System.Text;
using Microsoft.Dynamics.Framework.UI.Extensibility;
using Itenso.Rtf;
using Itenso.Rtf.Parser;
using Itenso.Rtf.Support;
using Itenso.Rtf.Converter.Image;
using Itenso.Rtf.Converter.Html;
using Itenso.Rtf.Interpreter;
using System.Drawing.Imaging;
namespace RTF2HTMLConverter
{
[ControlAddInExport("RTF2HTMLConverter")] //5a33fb4258a0a66c
public class Converter
{
string HTML;
public string RTF
{
get
{
return HTML;
}
set
{
MemoryStream RTFStream = new MemoryStream(Encoding.UTF8.GetBytes(RTF));
// Parse RTF
IRtfGroup RTFStructure;
RtfParserListenerStructureBuilder StructureBuilder = new RtfParserListenerStructureBuilder();
RtfParser Parser = new RtfParser(StructureBuilder);
Parser.IgnoreContentAfterRootGroup = true;
Parser.Parse(new RtfSource(RTFStream));
RTFStructure = StructureBuilder.StructureRoot;
RtfVisualImageAdapter imageAdapter = new RtfVisualImageAdapter("C:\\TEMP\\",ImageFormat.Jpeg);
// Interpret RTF
IRtfDocument RTFDocument;
RtfInterpreterSettings InterpreterSettings = new RtfInterpreterSettings();
InterpreterSettings.IgnoreDuplicatedFonts = true;
InterpreterSettings.IgnoreUnknownFonts = true;
RTFDocument = RtfInterpreterTool.BuildDoc(RTFStructure, InterpreterSettings);
// Convert RTF to HTML
RtfHtmlConvertSettings HTMLConvertSettings = new RtfHtmlConvertSettings();
HTMLConvertSettings.Title = "Converted from RTF";
HTMLConvertSettings.IsShowHiddenText = true;
HTMLConvertSettings.UseNonBreakingSpaces = true;
RtfHtmlConverter HTMLConverter = new RtfHtmlConverter(RTFDocument, HTMLConvertSettings);
HTML = HTMLConverter.Convert();
}
}
}
}
I'm stuck with this line:
RTFDocument = RtfInterpreterTool.BuildDoc(RTFStructure, InterpreterSettings);
the possible overloads:
public static IRtfDocument BuildDoc(IRtfGroup rtfDocument, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(IRtfSource rtfTextSource, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(Stream rtfTextSource, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(string rtfText, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(TextReader rtfTextSource, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(IRtfGroup rtfDocument, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(IRtfSource rtfTextSource, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(Stream rtfTextSource, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(string rtfText, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners); public static IRtfDocument BuildDoc(TextReader rtfTextSource, IRtfInterpreterSettings settings, params IRtfInterpreterListener[] listeners);
not matter what I try I get this
"The function call was ambiguous. No matching method was found."
this is the C/AL code
Name DataType Subtype Length
RtfSource Text
MemoryStream DotNet System.IO.MemoryStream.'mscorlib'
Encoding DotNet System.Text.Encoding.'mscorlib'
Convert DotNet System.Convert.'mscorlib'
--PARSE Boolean
IRtfGroup DotNet Itenso.Rtf.IRtfGroup.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'
RtfGroup DotNet Itenso.Rtf.Model.RtfGroup.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'
RtfParserListenerStructureBuilder DotNet Itenso.Rtf.Parser.RtfParserListenerStructureBuilder.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'
RtfParser DotNet Itenso.Rtf.Parser.RtfParser.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'
RtfStructureBuilder DotNet Itenso.Rtf.Parser.RtfParserListenerStructureBuilder.'Itenso.Rtf.Parser, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'
RtfVisualImageAdapter DotNet Itenso.Rtf.Converter.Image.RtfVisualImageAdapter.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'
ImageFormat DotNet System.Drawing.Imaging.ImageFormat.'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
--INTERPRET Boolean
IRtfDocument DotNet Itenso.Rtf.IRtfDocument.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'
RtfDocument DotNet Itenso.Rtf.Model.RtfDocument.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'
RtfInterpreterSettings DotNet Itenso.Rtf.Interpreter.RtfInterpreterSettings.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'
IRtfInterpreterSettings DotNet Itenso.Rtf.IRtfInterpreterSettings.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'
RtfInterpreterTool DotNet Itenso.Rtf.Support.RtfInterpreterTool.'Itenso.Rtf.Interpreter, Version=1.7.0.0, Culture=neutral, PublicKeyToken=d7f23b760ed5c748'
Documentation()
OnRun()
RtfSource := '{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang2057{\fonttbl{\f0\fnil\fcharset0 Calibri;}}{\*\generator Riched20 10.0.14393}\viewkind4\uc1\pard\sa200\sl276\slmult1\b\f0\fs22\lang9 TEST\b0\par}';
MemoryStream := MemoryStream.MemoryStream(Convert.ToByte(Encoding.GetEncoding('UTF8').GetBytes(RtfSource)));
// Parse RTF
IRtfGroup := RtfGroup;
RtfParserListenerStructureBuilder := RtfParserListenerStructureBuilder.RtfParserListenerStructureBuilder;
RtfParser := RtfParser.RtfParser;
RtfParser.AddParserListener(RtfParserListenerStructureBuilder);
RtfParser.IgnoreContentAfterRootGroup := TRUE;
RtfParser.Parse(MemoryStream);
RtfStructureBuilder := RtfParserListenerStructureBuilder.StructureRoot;
RtfVisualImageAdapter := RtfVisualImageAdapter.RtfVisualImageAdapter('C:\TEMP\',ImageFormat.Jpeg);
//Interpret RTF
IRtfDocument := RtfDocument;
IRtfInterpreterSettings := RtfInterpreterSettings;
RtfInterpreterSettings := RtfInterpreterSettings.RtfInterpreterSettings;
RtfInterpreterSettings.IgnoreDuplicatedFonts := TRUE;
RtfInterpreterSettings.IgnoreUnknownFonts := TRUE;
RtfDocument := RtfInterpreterTool.BuildDoc(RtfGroup,RtfInterpreterSettings);
any ideas?
0
Best Answer
-
My guess would be that the optional parameter (the one marked bye the keyword params in the C# code) is causing the trouble as C/AL does not work with optional parameters.
You probably need to instantiate an empty array of type IRtfInterpreterListener. You can do that like this:DotNetArray := DotNetArray.CreateInstance(GETDOTNETTYPE(IRtfInterpreterListener),0);
Where DotNetArray refers to System.Array and IRtfInterpreterListener refers to the interface in your Itenso DLL.
Then you call BuildDoc like with the array as the last parameter:RtfDocument := RtfInterpreterTool.BuildDoc(RtfGroup,RtfInterpreterSettings,DotNetArray);
1
Answers
-
I'm not a .net pro here, but whenever I scrambled with the interop I (at least think it was the case) that you have to use F5 to select the proper overload of a function for it to work.
Just a shot in the blue, but maybe it helps.Austrian NAV/BC Dev0 -
-
I've had issues when the options get too long. i.e. the length of the various parameters. Seems like NAV has some stringlength it can handle, and if the total length of the overload description goes over, then NAV fails.
Only solution I have found is to break it down and call the various bits individually.Don't just take my word for it, test it yourself0 -
My guess would be that the optional parameter (the one marked bye the keyword params in the C# code) is causing the trouble as C/AL does not work with optional parameters.
You probably need to instantiate an empty array of type IRtfInterpreterListener. You can do that like this:DotNetArray := DotNetArray.CreateInstance(GETDOTNETTYPE(IRtfInterpreterListener),0);
Where DotNetArray refers to System.Array and IRtfInterpreterListener refers to the interface in your Itenso DLL.
Then you call BuildDoc like with the array as the last parameter:RtfDocument := RtfInterpreterTool.BuildDoc(RtfGroup,RtfInterpreterSettings,DotNetArray);
1 -
kaspermoerch wrote: »My guess would be that the optional parameter (the one marked bye the keyword params in the C# code) is causing the trouble as C/AL does not work with optional parameters.
You probably need to instantiate an empty array of type IRtfInterpreterListener. You can do that like this:DotNetArray := DotNetArray.CreateInstance(GETDOTNETTYPE(IRtfInterpreterListener),0);
Where DotNetArray refers to System.Array and IRtfInterpreterListener refers to the interface in your Itenso DLL.
Then you call BuildDoc like with the array as the last parameter:RtfDocument := RtfInterpreterTool.BuildDoc(RtfGroup,RtfInterpreterSettings,DotNetArray);
Thank you very much! It worked!1
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
