views:

182

answers:

2

We have a working Silverlight 3 project. After changing the target framework to Silverlight 4 the application won't start anymore. It throws an exception in the following line in the generated InitializeComponent() method:

System.Windows.Application.LoadComponent(this, new System.Uri("/SLAppMain;component/App.xaml", System.UriKind.Relative));

Here is the exception (note the inner exception):

System.Windows.Markup.XamlParseException occurred
  Message= [Line: 0 Position: 0]
  LineNumber=0
  LinePosition=0
  StackTrace:
       bei System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
  InnerException: System.TypeLoadException
       Message=Der Typ 'System.Security.AllowPartiallyTrustedCallersAttribute' konnte nicht aus der mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e -Assembly geladen werden.
       StackTrace:
            bei System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
            bei System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
            bei System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
            bei 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)
            bei System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
            bei System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent)
            bei System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
            bei System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
            bei System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
            bei MS.Internal.XamlSchemaContext.ProcessXmlnsDefinitions(Assembly assembly, String assemblyName)
            bei MS.Internal.XamlSchemaContext.EnsureManagedAssemblyAttributesLoaded()
       InnerException: 

The problem is that the type System.Security.AllowPartiallyTrustedCallersAttribute is not contained in the Silverlight version of mscorlib.dll.

I have no idea how to fix this nor where to look for causes. Has anyone encountered this problem? What could possibly cause this error?

A: 

Hi there,

the AllowPartiallyTrustedCallersAttribute class does not exist in SL 4 (neither in mscorlib, nor anywhere else) and did not exist in SL 3 either. So there must be more than just the conversion from SL 3 to SL 4 to this I guess - is AllowPartiallyTrustedCallersAttribute used in your code somewhere?

Cheers, Alex

EDIT: Actually, you might want to take a look into your app's AssemblyInfo.cs (in the Properties folder). Perhaps the attribute is used there like

[assembly: AllowPartiallyTrustedCallers(true)]

. You could then simply remove it and see what happens...

alexander.biskop
I searched the entire solution and didn't find the attribute.
Did you search for "AllowPartiallyTrustedCallersAttribute" or "AllowPartiallyTrustedCallers"? You should do a search for "AllowPartiallyTrustedCallers", because the "-Attribute" part can be omitted when it's used.
alexander.biskop
I did exactly that.
This is some strange stuff...Actually, I didn't come across AllowPartiallyTrustedCallers in the Silverlight world so far; only in XBAP/ClickOnce scenarios in WPF. I fear I'm at my wits' end here. There's only another two things coming to my mind, but only as hints on where to look further maybe: One thing is the strong naming/assembly signing stuff. Maybe something got messed up there during the conversion. Second thing is: I once had a case where the conversion wizard did not adapt some of the assembly refs to the new version of SL (i.e. the 3.0 versions were still referenced).
alexander.biskop
A: 

Do you use Unity for silverlight in your project ? I had exactly the same problem yesterday, and the error disappeared when I de-referenced unity

mCasamento