在vs 2005里面
我建立了一个解决方案,里面有一个web项目,一个类库
在类库里面,我做如下引用:
[DllImport("kernel32.dll",CharSet=System.Runtime.InteropServices.CharSet.Auto)]
public   unsafe   static   extern   int   FormatMessage(int   dwFlags,   
 ref   IntPtr   lpSource,   
 int   dwMessageId,
 int   dwLanguageId,   
 ref   String   lpBuffer,   int   
 nSize,   
 IntPtr   *Arguments);在web项目中,添加对类库的引用
在web项目的default.aspx里面引用类库中的这个方法在编译的时候,把类库的项目属性中的"允许不安全代码"设为true,编译通过可是上传到web环境后,运行default.aspx,却出现如下错误:
不安全代码只会在使用 /unsafe 编译的情况下出现请问,我应该怎么做?

解决方案 »

  1.   

    把不安全代码写在
    unsafe
    {}
      

  2.   

    "配置属性"中的改成"允许不安全代码块" 改成true
      

  3.   

    发表于:2007-06-12 11:34:373楼 得分:0 
    "配置属性 "中的改成 "允许不安全代码块 "   改成true ========================
    在web项目中没这个选项好不
      

  4.   

    在web.conf 的 configuration 中 加入如下:  <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" warningLevel="4"
                    extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" compilerOptions="/unsafe+" />
        </compilers>
      </system.codedom>
    肯定好用,我也是找了好久。    给分。