该程序集不允许部分信任的调用者

时间:2009-11-05 22:33:58

标签: c# .net

我在服务器计算机上开发了c#gui应用程序,现在我想从客户端运行它。

通过映射目录访问aplication。

但是,当我运行它时,出现下一个错误:

> See the end of this message for
> details on invoking  just-in-time
> (JIT) debugging instead of this dialog
> box.
> 
> ************** Exception Text ************** System.Security.SecurityException:
> That assembly does not allow partially
> trusted callers.    at
> System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly
> asm, PermissionSet granted,
> PermissionSet refused,
> RuntimeMethodHandle rmh,
> SecurityAction action, Object demand,
> IPermission permThatFailed)    at
> Yobs01.Form1.button1_Click(Object
> sender, EventArgs e)    at
> System.Windows.Forms.Control.OnClick(EventArgs
> e)    at
> System.Windows.Forms.Button.OnClick(EventArgs
> e)    at
> System.Windows.Forms.Button.OnMouseUp(MouseEventArgs
> mevent)    at
> System.Windows.Forms.Control.WmMouseUp(Message&
> m, MouseButtons button, Int32 clicks) 
> at
> System.Windows.Forms.Control.WndProc(Message&
> m)    at
> System.Windows.Forms.ButtonBase.WndProc(Message&
> m)    at
> System.Windows.Forms.Button.WndProc(Message&
> m)    at
> System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&
> m)    at
> System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
> m)    at
> System.Windows.Forms.NativeWindow.Callback(IntPtr
> hWnd, Int32 msg, IntPtr wparam, IntPtr
> lparam) The action that failed was:
> LinkDemand The Zone of the assembly
> that failed was: Intranet
> 
> 
> ************** Loaded Assemblies ************** mscorlib
>     Assembly Version: 2.0.0.0
>     Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
>     CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
> ---------------------------------------- Yobs01
>     Assembly Version: 1.0.0.0
>     Win32 Version: 1.0.0.0
>     CodeBase: file:///Z:/Debug/Yobs01.exe
> ---------------------------------------- System.Windows.Forms
>     Assembly Version: 2.0.0.0
>     Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
>     CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
> ---------------------------------------- System
>     Assembly Version: 2.0.0.0
>     Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
>     CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
> ---------------------------------------- System.Drawing
>     Assembly Version: 2.0.0.0
>     Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
>     CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
> ---------------------------------------- System.Data.SqlServerCe
>     Assembly Version: 3.5.1.0
>     Win32 Version: 3.5.5692.0
>     CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Data.SqlServerCe/3.5.1.0__89845dcd8080cc91/System.Data.SqlServerCe.dll
> ---------------------------------------- System.Data
>     Assembly Version: 2.0.0.0
>     Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
>     CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
> ---------------------------------------- System.Transactions
>     Assembly Version: 2.0.0.0
>     Win32 Version: 2.0.50727.1433 (REDBITS.050727-1400)
>     CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
> ----------------------------------------
> 
> ************** JIT Debugging ************** To enable just-in-time (JIT) debugging, the .config file for
> this application or computer
> (machine.config) must have the
> jitDebugging value set in the
> system.windows.forms section. The
> application must also be compiled with
> debugging enabled.
> 
> For example:
> 
> <configuration>
>     <system.windows.forms jitDebugging="true" />
> </configuration>
> 
> When JIT debugging is enabled, any
> unhandled exception will be sent to
> the JIT debugger registered on the
> computer rather than be handled by
> this dialog box.

我在Assembly.cs中添加了下一行

[assembly: AllowPartiallyTrustedCallers]

但它没有帮助,错误仍然存​​在。

它在dotnet 3.5框架中。

你可以帮我解决这个问题吗?

提前谢谢你!

2 个答案:

答案 0 :(得分:3)

是的,我做到了!!!

你必须跑......

  

caspol -m -ag 1 -url   “file:// \ server \ mydir *”FullTrust   <独家

来自客户端计算机,而不是来自服务器!

答案 1 :(得分:0)

不是你的程序集必须用这个属性标记,它是你正在调用的程序集。

基本上这个异常告诉你你正在调用的程序集不允许陌生人调用它。你的集会是一个陌生人。要使它不是陌生人,您需要授予它完全信任,或将AllowPartialCallers属性应用于引用的程序集(如果它是您的程序集)