4
votes

For some reason Coldfusion is having an issue with accessing the parent methods of one of the objects it creates.

consider this code:

<cfscript>
  variables.sHTML = '<html><head><title></title></head><body><p>Hello <strong>World</strong></p></body></html>';

  try{
    variables.sAltChunkID = "altChunk1";
    variables.sExportDirectory = application.sSecureExportPath&'int'&'\word\';
    variables.sDLLPath = 'C:\Program Files (x86)\Open XML SDK\V2.0\lib\DocumentFormat.OpenXml.dll';

    variables.sFileName = "testI.docx";

    variables.sFileToWrite = variables.sExportDirectory&'#variables.sFileName#';

    variables.enumWordProcessingDocumentType = createObject("dotnet","DocumentFormat.OpenXml.WordprocessingDocumentType","#variables.sDLLPath#").init().Document;

    variables.oDocument = createObject("dotnet","DocumentFormat.OpenXml.Packaging.WordprocessingDocument","#variables.sDLLPath#").Create(variables.sFileToWrite,variables.enumWordProcessingDocumentType);

    variables.oMainDocument = variables.oDocument.AddMainDocumentPart();

    variables.oEncoding = createObject("dotnet","System.Text.UTF8Encoding").init();
    //variables.oMemoryStream = createObject("dotnet","System.IO.MemoryStream").init(variables.oEncoding.GetBytes(variables.sHTML));

    variables.enumAltChunk = createObject("dotnet","DocumentFormat.OpenXml.Packaging.AlternativeFormatImportPartType","#variables.sDLLPath#").html;

    variables.oFormatImportPart = variables.oMainDocument.AddAlternativeFormatImportPart(variables.enumAltChunk,variables.sAltChunkID);
    writeDump(variables.oFormatImportPart);

    variables.oFormatImportPart.FeedData(createObject("dotnet","System.IO.MemoryStream").init(variables.oEncoding.GetBytes(variables.sHTML)));
  } catch(Any e) {
    writeDump(e);
  }
</cfscript>

variables.oFormatImportPart has a parent method of FeedData(System.IO.Stream), however when I get to that line, Coldfusion hits me with an exception of:

Either there are no methods with the specified method name and argument types or the FeedData method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.

But as you can see from my Dump, FeedData does indeed exist as a method:

Coldfusion mocks me about the existance of a method

1
(Edit) Just a guess, but it might be a class loader issue. Try adding the sDLLPath path to all of your createObject calls. In particular, the one used to create the stream passed to FeedData(...) - Leigh
@Leigh So I've tried adding the sDLLPath on the oEncoding creation and the memorystream creation, but no dice. It still can't seem to find the FeedData method. - Jarede
Finally had a chance to try the code. After fixing a small syntax error, I unfortunately get the same result w/cF10, FWIW. Deleting the stubs and restarting had no effect. Certainly seems like it should work as both objects exists, and the parameter is an instance of System.IO.Stream. - Leigh
Cheers for looking. I'll probably just write a DLL that basically does this for me, passing it HTML and other arguments from coldfusion. Shouldn't have much trouble with that. - Jarede
For grins, I tried it with a System.IO.FileStream and it seemed to work. Not sure what the difference is, as both classes extend Stream. - Leigh

1 Answers

0
votes

FeedData is overloaded and expecting a Stream object. You are currently sending it an ambiguous object as it has not be cast to the proper type after your createObject call.