2011-07-18 20 views
7

¿Cómo puedo hacer que funcione mi implementación de aplicaciones?WPF ClickOnce y problema de confianza parcial

Creé un nuevo proyecto simple de WPF con Visual Studio 2010 e hice las siguientes modificaciones en las propiedades del proyecto: -> Firma: se creó el certificado de prueba y se firmaron los ensamblajes y manifiestos. No marcó la casilla "solo con el signo retrasado" -> Seguridad: casilla marcada "Habilitar una vez las configuraciones de seguridad" y el botón de opción "Esta es una configuración de confianza parcial". Zona: "Intranet local". -> Seguridad, Avanzado: depure esta aplicación con la configuración de seguridad seleccionada (yo elijo esta).

Al iniciar la depuración, obtengo una solicitud de permiso del tipo 'System.Security.Permissions.SecurityPermission, mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' fallido.

Durante la instalación, la aplicación se instalará pero no pasa nada al iniciarla. En otra computadora, se mostrará un bla bla que funciona (utilidad de inicio).

SO: Windows 7.

Con algunos experimentos, descubrí que la adición de la bandera UnmanagedCode a la SecurityPermission resolvió el problema. ¿Por qué una simple aplicación WPF (un mundo de saludo recién creado) necesita llamar a un código no administrado? Este es un agujero de seguridad tan grande como un volcán.

Gracias por cualquier sugerencia

+0

me encontré con un no tan buena solución: He cambiado la configuración de seguridad a medida y copie los permisos de (intranet local) en la aplicación .manifest. Cambié el permiso de seguridad a: . Esto parece ser un agujero de seguridad: la bandera "AllFlags". Es solo un hola mundo WPF. ¿Por qué demonios incluso necesita una autorización de seguridad? – yonexbat

+1

Finalmente encontré la bandera de SecurityPermission. La bandera que faltaba era UnmanagedCode. ¿Por qué se requiere un hello world WPF para llamar a unmanagedCode? – yonexbat

Respuesta

4

tarde a la fiesta, pero esto es lo que he encontrado (mientras tropezar con el mismo problema).

Parece que WPF Windowhace requiere UnmanagedCode permiso.

Extracto de Pro WPF 4.5 in C#: Windows Presentation Foundation in .NET 4.5 por Matthew MacDonald.

ClickOnce and Partial Trust


Y, aquí está el seguimiento de pila de excepción, cuando se ejecuta la aplicación WPF desplegado a través de ClickOnce en confianza parcial. Note la llamada a DemandUnmanagedCode función de SecurityHelper desde el constructor de Window:

InnerException: System.Security.SecurityException 
     Message=Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. 
     Source=mscorlib 
     StackTrace: 
      at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
      at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) 
      at System.Security.CodeAccessPermission.Demand() 
      at MS.Internal.SecurityHelper.DemandUnmanagedCode() 
      at System.Windows.Window..ctor() 
      at WPFClickOnceDeploySample.MainWindow..ctor() 

Y, aquí está la StackTrace completo:

System.Reflection.TargetInvocationException was unhandled 
    Message=Exception has been thrown by the target of an invocation. 
    Source=mscorlib 
    StackTrace: 
     at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) 
     at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) 
     at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) 
     at System.Activator.CreateInstance(Type type, Boolean nonPublic) 
     at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
     at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
     at System.Activator.CreateInstance(Type type, Object[] args) 
     at CreateInstance(Type type, Object[] arguments) 
     at System.Xaml.Schema.SafeReflectionInvoker.CreateInstance(Type type, Object[] arguments) 
     at System.Xaml.Schema.XamlTypeInvoker.CreateInstance(Object[] arguments) 
     at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args) 
     at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args) 
     at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx) 
     at System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property) 
     at System.Xaml.XamlWriter.WriteNode(XamlReader reader) 
     at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack``1 stack, IStyleConnector styleConnector) 
     at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) 
     at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) 
     at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) 
     at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc) 
     at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties) 
     at System.Windows.Application.DoStartup() 
     at System.Windows.Application.<.ctor>b__1(Object unused) 
     at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
     at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
     at System.Windows.Threading.DispatcherOperation.InvokeImpl() 
     at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) 
     at System.Threading.ExecutionContext.runTryCode(Object userData) 
     at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext 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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
     at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) 
     at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) 
     at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) 
     at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) 
     at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) 
     at System.Windows.Application.RunDispatcher(Object ignore) 
     at System.Windows.Application.RunInternal(Window window) 
     at System.Windows.Application.Run(Window window) 
     at System.Windows.Application.Run() 
     at WPFClickOnceDeploySample.App.Main() 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) 
     at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() 
     at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) 
     at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) 
     at System.Activator.CreateInstance(ActivationContext activationContext) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.runTryCode(Object userData) 
     at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: System.Security.SecurityException 
     Message=Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. 
     Source=mscorlib 
     StackTrace: 
      at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) 
      at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark) 
      at System.Security.CodeAccessPermission.Demand() 
      at MS.Internal.SecurityHelper.DemandUnmanagedCode() 
      at System.Windows.Window..ctor() 
      at WPFClickOnceDeploySample.MainWindow..ctor() 
     InnerException: 
+0

Ahora trabajo para una gran compañía y la implementación de ClickOnce no se usa allí. Las aplicaciones de Windows 8 harán que ClickOnce se vuelva obsoleto. Bien, MS a veces cambia la estrategia como la ropa interior. – yonexbat

+0

@yonexbat No veo cómo Windows8 está haciendo ClickOnce obselete, la tienda de Windows8 es totalmente diferente de ClickOnce ... –