为什么会出现奇怪的索引错误在VS 2010中? [英] Why am I getting strange indexing error in VS 2010?
问题描述
我创建了一个C#的Web在Visual Studio 2010然后从另一个VS解决方案应用我复制了一些ASPX文件(及code后面)。我不得不去通过,并清理一些参考和东西。最后,我把一切都清理除了一个奇怪的事情。在VS我看到以下行code的红色波浪线:
如果(的Request.QueryString [B]!= NULL)
的线是所述的Request.QueryString [b的]部分之下。当我将鼠标悬停在它我看到了以下错误消息:
无法适用与[]索引到类型的前pressionSystem.Collections.Specialized.NameValueCollection
块引用>这是在后面的页面上的code Page_Load事件。真正奇怪的是,如果我建这个项目它建立罚款没有任何问题,红色波浪线消失。不过,如果我关闭并重新打开该文件 - 我看到了相同的红色波浪线和VS再次抱怨
任何想法?我百思不得其解。我试着重建,清洁液,关闭VS和重新开放,等等。
编辑:这里是文件的一部分,使用
使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.ServiceModel;
使用System.Collections.Specialized;此外,这里距离ASPX文件头:
<%@页面语言=C#AutoEventWireup =真codeBehind =beamswitch.aspx.cs继承=AIMSWeb.data.beamswitch%GT ;
解决方案所以,我想我找到了这是为什么发生。我正在构建ASP.NET应用程序将是一个客户,我已经建立了一个WCF服务。创建客户端的过程中的一部分是使用微软实用程序生成一个app.config文件和一个proxy.cs文件。这些文件然后在我的ASP.NET应用程序来提供代理code,我可以使用,这样我可以从我的ASP.NET文件调用该服务。当我从我的解决方案中删除这些文件中的问题,就走开了。
具体我猜测,这个问题曾与事实,在我服务的方法之一是想序列化和发送的Request.Form对象作为参数做。我想知道如果我proxy.cs文件中的code是导致冲突或什么的。我要尝试重建我的服务也许使用字典什么的来代替,然后看看是否能解决这个问题。很奇怪。感谢所有的帮助。
I created a C# Web Application in Visual Studio 2010. Then I copied some ASPX files (and the code behind) from another VS solution. I had to go through and clean up some references and stuff. Eventually I got everything cleaned up except one strange thing. In VS I am seeing the red squiggly lines on the following line of code:
if (Request.QueryString["b"] != null)
The lines are beneath the Request.QueryString["b"] portion. When I hover over it I see the following error message:
Cannot apply indexing with [] to an expression of type 'System.Collections.Specialized.NameValueCollection'
This is in the Page_Load event for the code behind on a page. The really strange thing is that if I build the project it builds fine without any problems and the red squiggly lines go away. But then if I close and re-open the file - I see the same red squiggly lines and VS is complaining again.
Any ideas? I am baffled. I tried rebuilding, cleaning the solution, closing VS and re-opening, etc.
EDIT: Here is the using part of the file.
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ServiceModel; using System.Collections.Specialized;
Also, here is the header from the ASPX file:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="beamswitch.aspx.cs" Inherits="AIMSWeb.data.beamswitch" %>
解决方案So I think I found out why this was happening. The ASP.NET application that I am building is going to be a client to a WCF Service that I already built. Part of the process of creating the client is using the Microsoft utility to generate an app.config file and a proxy.cs file. Those files are then used in my ASP.NET application to provide proxy code that I can use so that I can call the service from my ASP.NET files. When I removed those files from my solution the problem went away.
Specifically I am guessing that the problem had to do with the fact that one of the methods in my service was trying to serialize and send the Request.Form object as a parameter. I am wondering if the code in my proxy.cs file was causing conflicts or something. I am going to try rebuilding my service to maybe use a dictionary or something instead and then see if that fixes the issue. Very strange. Thanks for all of the help.
这篇关于为什么会出现奇怪的索引错误在VS 2010中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!