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

Null reference exception when using AcrylicWindow from Excel VSTO Addin #87

Open
mihaicupsuite opened this issue Mar 15, 2020 · 2 comments · May be fixed by #156
Open

Null reference exception when using AcrylicWindow from Excel VSTO Addin #87

mihaicupsuite opened this issue Mar 15, 2020 · 2 comments · May be fixed by #156

Comments

@mihaicupsuite
Copy link

The offending code:

public static ImageSource AppIcon{
get{
if (appIcon == null){
var path = System.Reflection.Assembly.GetEntryAssembly().Location;

Problem is that for this type of application the EntryAssembly is null.

@mihaicupsuite
Copy link
Author

The following code seems to work ok as fallback in my case, but might not be the desired outcome for everybody.

public static ImageSource AppIcon
{
get
{
if (appIcon == null)
{
var assembly = System.Reflection.Assembly.GetEntryAssembly();
if (assembly == null)
assembly = System.Reflection.Assembly.GetCallingAssembly();
var path = assembly.Location;
appIcon = GetIcon(path);
}
return appIcon;
}
protected set { appIcon = value; }
}

@svr333
Copy link

svr333 commented Nov 19, 2021

I have come to experience the same issue, more or less;

After updating from 0.6.1 to 0.9.0 (using 0.9.0 so AcrylicWindow works on Windows 11), I get a NullReferenceException.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at SourceChord.FluentWPF.Utility.IconHelper.get_AppIcon()

This is the part of the stacktrace Im focusing on.
I'll look for a workaround for the moment but it would be useful if I knew why this issue started occurring after updating

Full Stacktrace

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
   at object RuntimeMethodHandle.InvokeMethod(object target, object[] arguments, Signature sig, bool constructor)
   at object System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(object obj, object[] parameters, object[] arguments)
   at object System.Reflection.RuntimeMethodInfo.Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
   at object System.Reflection.RuntimePropertyInfo.GetValue(object obj, object[] index)
   at bool System.Windows.Markup.StaticExtension.GetFieldOrPropertyValue(Type type, string name, out object value)
   at object System.Windows.Markup.StaticExtension.ProvideValue(IServiceProvider serviceProvider)
   at object MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)
   at bool System.Xaml.XamlObjectWriter.Logic_ProvideValue(ObjectWriterContext ctx)
   at void System.Xaml.XamlObjectWriter.Logic_AssignProvidedValue(ObjectWriterContext ctx)
   at void System.Xaml.XamlObjectWriter.WriteEndMember()
   at void System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
   at void System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
   at DependencyObject System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List<DependencyObject> affectedChildren, UncommonField<Hashtable> templatedNonFeChildrenField)
   at DependencyObject System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List<DependencyObject> affectedChildren)
   at bool System.Windows.StyleHelper.ApplyTemplateContent(UncommonField<HybridDictionary[]> dataField, DependencyObject container, FrameworkElementFactory templateRoot, int lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
   at bool System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField<HybridDictionary[]> templateDataField, FrameworkElement container)
   at bool System.Windows.FrameworkElement.ApplyTemplate()
   at Size System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at void System.Windows.UIElement.Measure(Size availableSize)
   at void System.Windows.Interop.HwndSource.SetLayoutSize()
   at void System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   at void System.Windows.Window.SetRootVisual()
   at void System.Windows.Window.SetRootVisualAndUpdateSTC()
   at void System.Windows.Window.SafeCreateWindowDuringShow()
   at object System.Windows.Window.ShowHelper(object booleanBox)
   at void AudioBand.UI.SettingsWindow.SettingsWindowMessageHandler(SettingsWindowMessage msg) in C:/Users/vanro/Documents/Programming/cs/audio-band/src/AudioBand/UI/Toolbar/SettingsWindow.xaml.cs:line 97
   at void AudioBand.Messages.MessageBus.Publish<TMessage>(TMessage message, string caller) in C:/Users/vanro/Documents/Programming/cs/audio-band/src/AudioBand/Messages/MessageBus.cs:line 56
   at void MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, bool userInitiated)
   at object System.Windows.Controls.MenuItem.InvokeClickAfterRender(object arg)
   at object System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, object args, int numArgs)
   at object System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, Delegate callback, object args, int numArgs, Delegate catchHandler)
   at void System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at void MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, object state)
   at void System.Windows.Threading.DispatcherOperation.Invoke()
   at void System.Windows.Threading.Dispatcher.ProcessQueue()
   at IntPtr System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
   at IntPtr MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
   at object MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o)
   at object System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, object args, int numArgs)
   at object System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, Delegate callback, object args, int numArgs, Delegate catchHandler)
   at object System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, object args, int numArgs)
   at IntPtr MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam) ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at ImageSource SourceChord.FluentWPF.Utility.IconHelper.get_AppIcon()
   --- End of inner exception stack trace ---
---END OF EXCEPTION---
---ORIGINAL EXCEPTION---
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at SourceChord.FluentWPF.Utility.IconHelper.get_AppIcon()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at System.Windows.Markup.StaticExtension.GetFieldOrPropertyValue(Type type, String name, Object& value)
   at System.Windows.Markup.StaticExtension.ProvideValue(IServiceProvider serviceProvider)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CallProvideValue(MarkupExtension me, IServiceProvider serviceProvider)
   at System.Xaml.XamlObjectWriter.Logic_ProvideValue(ObjectWriterContext ctx)
   at System.Xaml.XamlObjectWriter.Logic_AssignProvidedValue(ObjectWriterContext ctx)
   at System.Xaml.XamlObjectWriter.WriteEndMember()
   at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
   at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
   at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
   at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
   at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
   at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
   at System.Windows.FrameworkElement.ApplyTemplate()
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Interop.HwndSource.SetLayoutSize()
   at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   at System.Windows.Window.SetRootVisual()
   at System.Windows.Window.SetRootVisualAndUpdateSTC()
   at System.Windows.Window.SafeCreateWindowDuringShow()
   at System.Windows.Window.ShowHelper(Object booleanBox)
   at AudioBand.UI.SettingsWindow.SettingsWindowMessageHandler(SettingsWindowMessage msg) in C:\Users\vanro\Documents\Programming\cs\audio-band\src\AudioBand\UI\Toolbar\SettingsWindow.xaml.cs:line 97
   at AudioBand.Messages.MessageBus.Publish[TMessage](TMessage message, String caller) in C:\Users\vanro\Documents\Programming\cs\audio-band\src\AudioBand\Messages\MessageBus.cs:line 56
   at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated)
   at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg)
   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.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   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)
---END OF ORIGINAL EXCEPTION```

svr333 added a commit to svr333/FluentWPF that referenced this issue Nov 20, 2021
@svr333 svr333 linked a pull request Nov 20, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants