Search code examples
c#prism.net-assemblycustom-attributes

Cross assembly Attributes in prism


I wrote a custom attribute which I used in a module "DomainModule", The Attribute uses a helper class in a referenced assembly "Assembly A" The Attribute definition is there:

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class RidTabAttribute : Attribute

And the Helper Class "Assembly A" uses "Assembly B" or here: Zepers.Ribb Which brings the information and resources to the module view.

I'm given an error mentioned below, please tell me how can I fix this.

Error Line : (In Domain Module)

return type.GetCustomAttributes(typeof(T), true).OfType<T>();

Error Outline:

{"Could not load file or assembly 'Zelopers.Ribb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.":"Zelopers.Ribb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"}

StackTrace :

Could not load file or assembly 'Zelopers.Ribb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' 
or one of its dependencies. The system cannot find the file specified.

   at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
   at System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
   at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
   at Zelopers.Prism.RibbonHelper.XamRibbonRegionBehavior.GetCustomAttributes[T](Type type) in e:\Wyrocco\ProjectsHall\Xz\Inside\Src\Common\Zepers.RibbonHelper\XamRibbonRegionBehavior.cs:line 58
   at Zelopers.Prism.RibbonHelper.XamRibbonRegionBehavior.ActiveViews_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) in e:\Wyrocco\ProjectsHall\Xz\Inside\Src\Common\Zelopers.RibbonHelper\XamRibbonRegionBehavior.cs:line 40
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.NotifyAdd(IList items, Int32 newStartingIndex)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.NotifyAdd(Object item)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.OnItemMetadataChanged(Object sender, EventArgs e)
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at Microsoft.Practices.Prism.Regions.ItemMetadata.InvokeMetadataChanged()
   at Microsoft.Practices.Prism.Regions.ItemMetadata.DependencyPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at Microsoft.Practices.Prism.Regions.Region.Activate(Object view)
   at Microsoft.Practices.Prism.Regions.SingleActiveRegion.Activate(Object view)
   at Microsoft.Practices.Prism.Regions.ContentControlRegionAdapter.<>c__DisplayClass2.<Adapt>b__1(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.NotifyAdd(IList items, Int32 newStartingIndex)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.NotifyAdd(Object item)
   at Microsoft.Practices.Prism.Regions.ViewsCollection.SourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at Microsoft.Practices.Prism.Regions.Region.InnerAdd(Object view, String viewName, IRegionManager scopedRegionManager)
   at Microsoft.Practices.Prism.Regions.Region.Add(Object view, String viewName, Boolean createRegionManagerScope)
   at...Common\Zepers.Prism\Base\ModuleBase.cs:line 42
   at Microsoft.Practices.Prism.Modularity.ModuleInitializer.Initialize(ModuleInfo moduleInfo)

Error Location in the Error Message Box :

   {System.Object _CreateCaObject(System.Reflection.RuntimeModule, System.IRuntimeMethodInfo, Byte**, Byte*, Int32*)}

Solution

  • In the project where you are calling the following line,

    return type.GetCustomAttributes(typeof(T), true).OfType<T>();
    

    add Zelopers.Ribb as a reference.