4

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

Jarede
  • 3,310
  • 4
  • 44
  • 68
  • (Edit) Just a guess, but it might be a [class loader issue](http://stackoverflow.com/questions/16818747/method-not-found-calling-net-method-with-list-from-coldfusion/16821072#16821072). Try adding the `sDLLPath` path to *all* of your createObject calls. In particular, the one used to create the stream passed to `FeedData(...)` – Leigh May 16 '14 at 14:35
  • @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 May 17 '14 at 12:20
  • 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 May 19 '14 at 16:23
  • 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 May 20 '14 at 06:30
  • 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 Jun 08 '14 at 16:11
  • I'll have a look at that tomorrow. I guess I never tried that myself. Would love to know why a `FileStream` works and not the `MemoryStream` – Jarede Jun 08 '14 at 21:35
  • Hm.. if you dump the two objects, CF reports the parent class of `MemoryStream` object is `System.Object`, not `System.IO.Stream` like with the `FileStream` object. That probably explains why the latter works, and the former does not. – Leigh Jun 09 '14 at 12:06

1 Answers1

0

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.

  • `FeedData` is not overloaded. That is just a generic error message which lists several *possible* causes. – Leigh Jun 08 '14 at 15:00
  • hmm.. it seems that you still need to cast it as it sees it as an Object and has no overload for the general object type. – CoderCamps.com Jun 09 '14 at 19:14
  • If you are not familiar with it, CF uses [jnbridge](http://www.jnbridge.com/) for .net interop. Direct casting is [not supported](https://wikidocs.adobe.com/wiki/display/coldfusionen/Using+.NET+classes) for complex objects. I think the bigger problem is that generated class does not seem to extend `Stream`. I am not sure why.. but if that is the case, then casting would not work anyway :/ – Leigh Jun 09 '14 at 23:06