views:

29

answers:

2

Hi All,

This morning I had an unusual issue with my Silverlight 4 app. I have been a big fan of IoC frameworks, so decided I will use Unity for my project. But as soon as I added the assembly to my project, I got this following error.

System.Windows.Markup.XamlParseException occurred

Message=Could not load type 'System.Security.AllowPartiallyTrustedCallersAttribute' from assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.

StackTrace: at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit) at MS.Internal.XamlSchemaContext.ProcessXmlnsDefinitions(Assembly assembly, String assemblyName) at MS.Internal.XamlSchemaContext.EnsureManagedAssemblyAttributesLoaded() InnerException:

Now if I remove the dll my app works absolutely fine. I have been scratching my head since morning and not having much luck with StackOverflow search or Google.

Any help is much appreciated.

Cheers---Jag

A: 

Hi,

This article might provide some useful information. It basically says that:

"the limitation when using Unity in a partial trust environment is that you cannot register and use mappings using the RegisterType methods where the target class is internal (C#), Friend (Visual Basic .NET), private (C#), or Private (Visual Basic .NET)."

Damian Schenkelman
Hi Damian, Thanks for the reply. I am not getting as far as writing any unity code. All I do is add the reference and the app blows up :-(
Jag
+1  A: 

Please verify that you're actually referencing the Silverlight assembly rather than the desktop one. The AllowPartiallyTrustedCallersAttribute class isn't in the Silverlight version.

Are you using Unity 2.0? If so, the DLL is named "Microsoft.Practices.Unity.Silverlight.dll". Is that the DLL you've added? If the ".Silverlight" isn't in the file name, then you're referencing the desktop dll instead.

Chris Tavares