开发者

Problem with conversion of existing project to Silverlight 4

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,开发者_JS百科 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?


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...


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


This walk through REALLY helped me with the same issue http://code.msdn.microsoft.com/RiaServices/Release/ProjectReleases.aspx?ReleaseId=5122


Doing a clean build followed by a full rebuild fixed this issue for me.


Dependencies with the same name will be quietly overwritten and packaged into a XAP after the compilation, so make sure that different target platforms of your projects don't build into the same output folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜