Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 1366 [details]
The attached T4 file gives me following error on Windows:
Der Code Generator 'TextTemplatingFileGenerator' ist abgestürzt. Unable to cast transparent proxy to type 'Mono.TextTemplating.CompiledTemplate'.
The error only happens if you add the T4 file to a existing project.
After closing and reopening the project the T4 works as expected.
That's very strange, I could have sworn I fixed this issue in this commit over a year ago: https://github.com/mono/monodevelop/commit/2aeb6a00be6fe25251e08e30ede1b49f0fd39281
You can run the T4 file correctly after reloading the project? Is this a problem for all new T4 files, or just the first?
I can repro this. I think the problem is still load contexts: http://msdn.microsoft.com/en-us/library/dd153782.aspx
Since MD loads addins (including MonoDevelop.TextTemplating) using Assembly.LoadFrom, it'll be in the load-from context. But the appdomain and the T4 engine are is using the default load context, so .NET thinks the types aren't the same when remoting and unwrapping them.
This is looking pretty hard to fix. It's really hard to debug because the only tool for tracking the load contexts is fuslogvw, which is really unreliable - it only shows a small subset of events, for some reason.
AFAICT problem is
1) appdomain serialization and proxy casts use Load calls, not LoadFrom calls. This affects e.g. objects passed as parameters to CreateInstanceFrom.
2) if Load can find the dll, it'll load it into the load context and use it, even if LoadFrom had already loaded it
3) Only if Load can't find the dll, can you can use an AssemblyResolve event handler. This handler can return a dll that's been loaded into the load-from context.
4) The AssemblyResolve handler has to be sent over to the appdomain in the first place, so it must be Load-able from in the appdomain's codebase.
5) MonoDevelop.TextTemplating must therefore be in the appdomain's codebase directory to implement and attach an AssemblyResolve handler directly, so it will be in the appdomain's Load context.
6) But MD loads MonoDevelop.TextTemplating using LoadFrom, because addins aren't in MD's CodeBase paths.
=> MonoDevelop.TextTemplating is always in mismatched contexts