Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Exception in SVGImage.ResolveUri() when application is published as Single File #105

Open
Ahrkylien opened this issue Mar 23, 2025 · 3 comments
Labels

Comments

@Ahrkylien
Copy link
Contributor

Describe the bug
When I build my application with <PublishSingleFile>true</PublishSingleFile> I get this exception:

Application: ....exe
CoreCLR Version: 6.0.2623.60508
.NET Version: 6.0.26
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Windows.Markup.XamlParseException: Initialization of 'SVGImage.SVG.SVGImage' threw an exception.
 ---> System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
   at System.IO.Path.Combine(String path1, String path2)
   at SVGImage.SVG.SVGImage.ResolveUri(Uri svgSource)
   at SVGImage.SVG.SVGImage.<>c__DisplayClass65_0.<SetImage>b__0(SVGRender render)
   at SVGImage.SVG.SVGImage.OnInitialized(EventArgs e)
   at System.Windows.FrameworkElement.TryFireInitialized()
   at System.Windows.FrameworkElement.EndInit()
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin)
   --- End of inner exception stack trace ---
   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
   at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1_0(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run()
   at ...App.Main()

To Reproduce
Simply do this where icon.svg is a Resource:

<svg:SVGImage UriSource="/Resources/Images/icon.svg" />

with:

<PublishSingleFile>true</PublishSingleFile>

Expected behavior
I expect it not to throw an exception :)

Additional context
I expect Assembly.GetExecutingAssembly().Location to be null:
https://github.com/dotnetprojects/SVGImage/blob/master/Source/SVGImage/SVG/SVGImage.cs#L678C76-L678C84
AppContext.BaseDirectory AppDomain.CurrentDomain.BaseDirectory would make more sense anyway.
keep backwards compatibility in mind:
https://ithy.com/article/app-directory-comparison-7smher8b

@Ahrkylien Ahrkylien added the bug label Mar 23, 2025
@Ahrkylien Ahrkylien changed the title [BUG] Exception in sdfsdf when build as Single File [BUG] Exception in SVGImage.ResolveUri() when build as Single File Mar 23, 2025
@Ahrkylien Ahrkylien changed the title [BUG] Exception in SVGImage.ResolveUri() when build as Single File [BUG] Exception in SVGImage.ResolveUri() when application is published as Single File Mar 23, 2025
@jogibear9988
Copy link
Member

I'm currently not actively using or working on this library, so you need to look for the issue yourself or hope someone fixes it. I've you look after it and create a pull req, I'll look to merge.

@Ahrkylien
Copy link
Contributor Author

Thanks for letting know.
Once my pull request has been merged will you make a new NuGet release afterwards?

@jogibear9988
Copy link
Member

yes

Ahrkylien added a commit to Ahrkylien/SVGImage that referenced this issue Mar 26, 2025
@Ahrkylien Ahrkylien mentioned this issue Mar 26, 2025
1 task
jogibear9988 added a commit that referenced this issue Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants