描述:error CS2001 異常

本文探讨了在IIS环境下运行C#代码时出现的编译异常,主要表现为找不到临时文件和未指定源文件的问题。通过调整IIS对C:WindowsTEMP目录的权限,成功解决了这一异常情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

異常描述:error CS2001: 找不到原始程式檔 'C:\Windows\TEMP\02o1wrzq.0.cs'
warning CS2008: 未指定原始程式檔

運行程式沒有異常,掛到IIS后出現異常,02o1wrzq.0.cs文件每次不一樣

此異常一般是IIS沒有C:\Windows\TEMP目錄的權限 ,增加權限即可

異常代碼

                WebClient wc = new WebClient();
                Stream stream = wc.OpenRead(url + "?WSDL");
                ServiceDescription sd = ServiceDescription.Read(stream);              
                ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
                sdi.AddServiceDescription(sd, "", "");
                CodeNamespace cn = new CodeNamespace(@namespace);
                //生成客戶端代理類代碼    
                CodeCompileUnit ccu = new CodeCompileUnit();
                ccu.Namespaces.Add(cn);
                sdi.Import(cn, ccu);               
                CSharpCodeProvider csc = new CSharpCodeProvider();
                ICodeCompiler icc = csc.CreateCompiler();                
                //設定編譯器參數 
                CompilerParameters cplist = new CompilerParameters();
                cplist.GenerateExecutable = false;
                cplist.GenerateInMemory = true;
                cplist.ReferencedAssemblies.Add("System.dll");
                cplist.ReferencedAssemblies.Add("System.XML.dll");
                cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
                cplist.ReferencedAssemblies.Add("System.Data.dll");
                //編譯代理类               
                CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu);
                if (true == cr.Errors.HasErrors) //此處異常
                {
                    System.Text.StringBuilder sb = new StringBuilder();
                    foreach (CompilerError ce in cr.Errors)
                    {
                        sb.Append(ce.ToString());
                        sb.Append(System.Environment.NewLine);
                    }
                    throw new Exception(sb.ToString());
                }       

 

D:\学习资料\毕业设计\C#app\App1\MainActivity.cs(28,40): error CS0117: “Resource.Layout”未包含“Main”的定义 D:\学习资料\毕业设计\C#app\App1\MainActivity.cs(31,53): error CS0117: “Resource.Id”未包含“btnScan”的定义 D:\学习资料\毕业设计\C#app\App1\MainActivity.cs(32,53): error CS0117: “Resource.Id”未包含“btnSend”的定义 D:\学习资料\毕业设计\C#app\App1\MainActivity.cs(33,59): error CS0117: “Resource.Id”未包含“listDevices”的定义 D:\学习资料\毕业设计\C#app\App1\MainActivity.cs(34,58): error CS0117: “Resource.Id”未包含“txtMessage”的定义 D:\学习资料\毕业设计\C#app\App1\MainActivity.cs(35,57): error CS0117: “Resource.Id”未包含“txtStatus”的定义 D:\学习资料\毕业设计\C#app\App1\MainActivity.cs(40,29): warning CS0618: “BluetoothAdapter.DefaultAdapter”已过时:“deprecated” D:\学习资料\毕业设计\C#app\App1\MainActivity.cs(92,16): error CS0246: 未能找到类型或命名空间名“Exception”(是否缺少 using 指令或程序集引用?) D:\学习资料\毕业设计\C#app\App1\MainActivity.cs(115,16): error CS0246: 未能找到类型或命名空间名“Exception”(是否缺少 using 指令或程序集引用?) D:\学习资料\毕业设计\C#app\App1\MainActivity.cs(133,20): error CS0246: 未能找到类型或命名空间名“Exception”(是否缺少 using 指令或程序集引用?) D:\学习资料\毕业设计\C#app\App1\MainActivity.cs(163,51): warning CS0618: “Intent.GetParcelableExtra(string?)”已过时:“deprecated” using Android.Bluetooth; using Android.Content; using Android.OS; using Android.Widget; using Android.App; using System.Collections.Generic; using Java.Util; using System.Text; using System.Threading.Tasks; using Android; [Activity(Label = "蓝牙通讯示例", MainLauncher = true)] public class MainActivity : Activity { private BluetoothAdapter _bluetoothAdapter; private ListView _listDevices; private Button _btnScan, _btnSend; private EditText _txtMessage; private TextView _txtStatus; private ArrayAdapter<string> _adapter; private BluetoothDevice _targetDevice; private BluetoothSocket _socket; private UUID _uuid = UUID.FromString("00001101-0000-1000-8000-00805F9B34FB"); // 标准SPP UUID protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main);
最新发布
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值