[MonoDevelop] Problems with assembly loading under TextTransform.exe

Tom Cook tom.k.cook at gmail.com
Wed Nov 25 12:13:26 UTC 2015


I've posted a sample project that demonstrates this problem (or one very
similar to it) at https://github.com/tomkcook/T4CSTest

To use it:


   - Open the T4CSTest solution in MonoDevelop.
   - Restore packages for the T4CSTest project.
   - Build the T4CSTest project (this is a library that uses the
   Microsoft.CodeAnalysis.* assemblies).  The Utilities class has a single
   method called GetFirstNamespace(string) that returns the code of the first
   namespace in the string it is passed.
   - Build the Templates project and run the resulting executable - this is
   a C# programme that shows that the GetFirstNamespace method working.
   - At the command-line:
   cd T4CSTest/Templates
   /usr/lib/monodevelop/AddIns/MonoDevelop.TextTemplating/TextTransform.exe
   -P=../T4CSTest/bin/Debug T4Template.tt

It produces the following output:

Invalid type Microsoft.CodeAnalysis.SyntaxTree for instance field
Microsoft.CodeAnalysis.SyntaxNode:_syntaxTree Processing 'T4Template.tt'
failed. (0,0): ERROR Error running transform:
System.Reflection.TargetInvocationException: Exception has been thrown by
the target of an invocation. ---> System.TypeLoadException: Failure has
occurred while loading a type. at T4CSTest.Utilities.GetFirstNamespace
(System.String code) <0x414484c0 + 0x0002f> in <filename unknown>:0 at
Microsoft.VisualStudio.TextTemplating.GeneratedTextTransformation5c65abe6.TransformText
() <0x41447fa0 + 0x00087> in <filename unknown>:0 at (wrapper
managed-to-native) System.Reflection.MonoMethod:InternalInvoke
(System.Reflection.MonoMethod,object,object[],System.Exception&) at
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[] parameters,
System.Globalization.CultureInfo culture) <0x7f32871ab780 + 0x000a1> in
<filename unknown>:0 --- End of inner exception stack trace --- at
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[] parameters,
System.Globalization.CultureInfo culture) <0x7f32871ab780 + 0x000ef> in
<filename unknown>:0 at System.Reflection.MethodBase.Invoke (System.Object
obj, System.Object[] parameters) <0x7f3286fe3cf0 + 0x0002a> in <filename
unknown>:0 at Mono.TextTemplating.CompiledTemplate.Process () <0x41447520 +
0x0036f> in <filename unknown>:0

On Wed, 25 Nov 2015 at 09:36 Tom Cook <tom.k.cook at gmail.com> wrote:

> I'm porting some T4 templates from the Microsoft .NET Framework to Mono.
> They use an in-house assembly called DataModelDefinition, which in turn
> uses the Microsoft.CodeAnalysis and Microsoft.CodeAnalysis.CSharp
> assemblies to process some C# code.
>
> When I try to run one of these templates, I get the following error:
>
> > $ TextTransform.exe -P=<path to assemblies> -o test.txt ProcessFiles.tt
> > <a bunch of expected output from my code>
> > Invalid type Microsoft.CodeAnalysis.SyntaxTree for instance field
> Microsoft.CodeAnalysis.SyntaxNode:_syntaxTree
> > Invalid type Microsoft.CodeAnalysis.SyntaxNode for instance field
> Microsoft.CodeAnalysis.SyntaxToken:parent
> > Failed to generate <path>/ProjectInfo.xml because :
> > Could not load type 'Microsoft.CodeAnalysis.SyntaxToken' from assembly
> 'Microsoft.CodeAnalysis, Version=0.6.0.0, Culture=neutral,
> PublicKeyToken=31bf3856ad364e35'.
> >
> > Stack trace:
> >   <a bunch of files within the DataModelDefinition assembly>
>
> But if I write a stand-alone console programme that references the same
> assemblies and invokes the same method, it works without a problem.
>
> What could cause the failure to load these types?
>
> I'm trying to put together a simple test case that demonstrates the
> problem; I'll get back when I've got something together.
>
> Regards,
> Tom
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/monodevelop-list/attachments/20151125/a62eaeea/attachment.html>


More information about the Monodevelop-list mailing list