Ref/ByRef parameters

Jan 12, 2008 at 10:29 PM
I ran into a bug where the Pipeline Builder inserted ampersands in code if the interface contained a ref parameter. Obviously the ampersand is incorrect in the output, but I realized there is probably a deeper problem going on. We're talking about a pretty serious isolation boundary - an app domain boundary. Because of this data is serializd and reference parameters may be a problem.

So, I wanted to start this discussion with two goals - one is a better understanding of how parameters work across the isolation boundary and whether by ref types (in my case an immutable reference type in a string, but it could otherwise be value types) can be passed.

The second goal is working out alternate design patterns. In my case, I'm generating code. I have an add-in that understands the particular metadata structure. I have five methods in my contract - one takes the xml metadata as a string, parses it, and returns a standard format for the host to request particular templates be run against. The other four geenrate code.

For these four methods, I pass a key into the XML (so only the add in needs to know the metadata structural details), and an assembly and template name (the templates are .NET files with VB 9 XML literals). More addins are likely later, but this is the current picture. The problem is that in addition to handing back a large string with the data to output, the add-in also needs to return the file name beause the pattern of the filename is currently known by the addin, not the host. It seems too chatty to call the add-in twice - once for the output text and once for the filename. Is serializing a structure with the two values the best approach? Are these the only two options?

I haven't thought about this problem very long, but it seemed one that will come up often as people are looking at best managing their add in contracts. So I thought it would be helpful to discuss it here.

Thanks for your input.

Feb 1, 2008 at 11:39 AM
I had same problem : could not use ref parameters in interfaces (working in C#... so, same problem as in VB), I get ampersands in generated code.
So, I am using Get functions that return values instead. Not very elegant though...

Mar 10, 2008 at 9:23 PM
Just to close the loop on this conversation. We've had some discussions internally and determined that it's possible to use ref and out parameters without breaking or losing the benifits of isolation. The latest PipelineBuilder CTP (March) includes support for automatically generating the views and adapters for contracts that have methods with ref/out parameters.