"The invoked member is not supported in a dynamic assembly" when creating SvgImage from XAML?
See original GitHub issueMy WPF project uses SvgImage
but I am getting an exception when the XAML form tries to load.
The project builds the XAML form into an assembly which is loaded by an unmanaged EXE at runtime through COM interop.
SvgImage
is used as follows:
<Fluent:SplitButton
...
l:RibbonImages.Source="{svgc:SvgImage Source=path/to/Images/filename.svg}">
What happens here is that l:RibbonImages
is a DependencyObject
that binds its source to some properties of the object its attached to. It does nothing directly to the SVG object itself; it just passes it through, essentially.
The immediate exception thrown is on that line of XAML code:
'System.Windows.Markup.XamlParseException' in PresentationFramework.dll
but I think this is rather generic; the inner exception is more interesting, and is as follows:
Message "Could not load file or assembly 'SharpVectors.Converters.Wpf, PublicKeyToken=b532964b8548be77' or one of its dependencies. The system cannot find the file specified." string
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at System.Windows.Baml2006.Baml2006SchemaContext.ResolveAssembly(BamlAssembly bamlAssembly)
at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlTypeToType(BamlType bamlType)
at System.Windows.Baml2006.Baml2006SchemaContext.ResolveBamlType(BamlType bamlType, Int16 typeId)
at System.Windows.Baml2006.Baml2006SchemaContext.GetXamlType(Int16 typeId)
at System.Windows.Baml2006.Baml2006Reader.Process_ElementStart()
at System.Windows.Baml2006.Baml2006Reader.Process_OneBamlRecord()
at System.Windows.Baml2006.Baml2006Reader.Process_BamlRecords()
at System.Windows.Baml2006.Baml2006Reader.Read()
at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
So basically it claims to fail to load the assembly at runtime - even though it builds fine & the DLL is copied to the output directory.
However at runtime in fact the DLL is not shown as loaded in the Visual Studio debugger Modules window.
Now an interesting variation in this inner exception will occur if I add a dummy line of code to a plain CS file in the project:
public static SharpVectors.Converters.SvgControl dummy = new SharpVectors.Converters.SvgControl();
The point of this line was just to see if it would throw there instead of in XAML. But in fact this line executes fine; since its static
it goes early and a breakpoint confirms it runs OK.
Later when it tries to load the XAML I get an exception on the same line as above, but the inner details are different:
InnerException {"The invoked member is not supported in a dynamic assembly."} System.Exception {System.NotSupportedException}
at System.Reflection.Emit.InternalAssemblyBuilder.get_CodeBase()
at SharpVectors.Converters.SvgImageBase.<>c.<GetEntryAssembly>b__24_4(Assembly assembly) in D:\Visual Studio\Workspaces\SharpVectors\Source\SharpVectorConvertersWpf\SvgImageBase.cs:line 410
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at SharpVectors.Converters.SvgImageBase.GetEntryAssembly() in D:\Visual Studio\Workspaces\SharpVectors\Source\SharpVectorConvertersWpf\SvgImageBase.cs:line 408
at SharpVectors.Converters.SvgImageBase.GetAppName() in D:\Visual Studio\Workspaces\SharpVectors\Source\SharpVectorConvertersWpf\SvgImageBase.cs:line 356
at SharpVectors.Converters.SvgImageExtension..ctor() in D:\Visual Studio\Workspaces\SharpVectors\Source\SharpVectorConvertersWpf\SvgImageExtension.cs:line 51
AFAIK there is no dynamic assembly creation going on, so I have no idea what this means. But in this scenario I can see that the DLL is loaded in the debugger.
My hunch is that both of these failure variants have the same root cause and just manifests itself differently depending on what code runs first.
Basically I’m at a loss how to debug this any further. But I hoped the latter information about how the CodeBase property fails might be a useful clue.
Thanks
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (4 by maintainers)
Top GitHub Comments
In fact, I can reproduce this now with controls from other libraries. So this doesn’t seem likely to be a problem specific to SharpVectors.
The multi-targets release 1.6 is now active.