question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"The invoked member is not supported in a dynamic assembly" when creating SvgImage from XAML?

See original GitHub issue

My 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:closed
  • Created 4 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DaveInCazcommented, Feb 7, 2020

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.

0reactions
paulushubcommented, May 17, 2020

The multi-targets release 1.6 is now active.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Loading plug-in DLL files, "The invoked member is not ...
This process worked fine while using .NET 2.0, but we are getting the "The invoked member is not supported in a dynamic assembly"...
Read more >
.NET Reflection - The invoked member is not supported in ...
This is because an Assembly is generated dynamically during the tests and the "GetExportedTypes()" is not supported on these assemblies.
Read more >
The invoked member is not supported in a dynamic assembly
Hello, Aspose.Words for .Net works fine on the development machine, but on the production machine it throws an exception (see attachment).
Read more >
Studio - About Libraries
When using Invoke Workflow File activity, make sure the invoked file is located in the same folder as the library project. The Launch...
Read more >
[Solved]-Loading plug-in DLL files, "The invoked member is ...
this error is occurring because assembly. load cannot be called upon dynamic assemblies. you must filter out the dynamic assemblies before using them....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found