Tôi đang ở giai đoạn kết thúc của mình về vấn đề này. Đôi khi tôi nhận được lỗi ở trên từ dịch vụ web asmx .Net 2.0 của tôi. Tôi đã có đúng XmlInclude() tại chỗ, và nó chỉ xuất hiện đôi khi - khi tôi xây dựng lại và cập nhật trang web, nó có thể hiển thị, nó có thể không, không vần điệu hay lý do. Nếu tôi di chuyển một số các XmlIncludes() xung quanh, xây dựng lại, và đẩy các thay đổi lên, lỗi thường biến mất.System.InvalidOperationException: Loại [XYZ] có thể không được sử dụng trong ngữ cảnh này. BUG Đã xác nhận
Trước khi có quá trình xây dựng tại chỗ chuyển đổi mọi thứ thành DLL, tôi đã sử dụng phương pháp triển khai ol xcopy tốt. Các lỗi xảy ra sau đó, quá, nhưng sau đó tất cả tôi phải làm là thêm một không gian vào tập tin được xác định tất cả các cuộc gọi XmlInclude(), và IIS sẽ biên dịch lại và lỗi sẽ biến mất.
Đối với giá trị của nó, có rất nhiều XmlIncludes được xác định, khoảng 100 hoặc hơn.
Bất kỳ ý tưởng nào?
Dưới đây là một đoạn:
namespace Courses{
[Serializable]
[XmlInclude(typeof(UserToCourse)),
XmlInclude(typeof(UserToCourseCollection)),
// ...lots more....
XmlInclude(typeof(ReadOnlySearchResultsRecordset<UserToCourse, UserToCourseCollection>)),
XmlInclude(typeof(AllCoursesByTrainingProgramCollection)),
XmlInclude(typeof(StartupObject))]
public partial class ServiceCallResult{
//..snipped class def
}
}
Edit: Dường như sắp xếp lại các XmlIncludes làm cho các lỗi biến mất, nhưng nó có thể hoặc không có thể trở lại lần sau tôi biên dịch và triển khai lại.
Chỉnh sửa # 2: OK, một số chi tiết khác. Buộc tái chế bằng cách thay đổi web.config không giải quyết được vấn đề, cũng như không khởi động lại IIS hoàn toàn. Vì lý do nào đó, nhật ký của tôi không được viết chính xác, vì vậy tôi chưa có dấu vết ngăn xếp.
Lần này, lỗi xảy ra đối với 2 phương pháp cụ thể. Tôi đã thực hiện thay đổi đối với global.asax (để cố gắng sửa lỗi ghi nhật ký ngăn xếp của mình), được xây dựng lại và cập nhật và một trong hai phương pháp bắt đầu hoạt động. Sau đó tôi chia lớp với XmlIncludes vào nó thành 2 lớp một phần, được xây dựng lại, cập nhật và cả hai phương thức đều bắt đầu hoạt động trở lại. Tôi không chắc liệu đây có phải là sự cố định vĩnh viễn hay không vào lúc này, bởi vì nó quá ngẫu nhiên; Tôi sẽ cập nhật lại chu kỳ xây dựng tiếp theo.
Chỉnh sửa # 3: Chắc chắn không phải là bản sửa lỗi vĩnh viễn và tôi vẫn chưa được nối vào đúng nơi để theo dõi ngăn xếp đầy đủ (mặc dù các nhật ký khác của tôi đều hoạt động tốt). Ugh. Tôi sẽ cập nhật một lần nữa vòng tiếp theo.
Chỉnh sửa # 4: Cuối cùng có dấu vết ngăn xếp. Nó không bắt trong Visual Studio, cũng không phải trong trình xử lý ngoại lệ toàn cầu trong global.asax của tôi. Đây là kết quả như được hiển thị khi gọi phương thức trực tiếp từ trình duyệt web:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.String[] may not be used in this context.
at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write119_ServiceCallResult(String n, String ns, ServiceCallResult o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write397_ServiceCallResult(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.ServiceCallResultSerializer277.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
Chỉnh sửa # 5:
Đây có thể là một triệu chứng của lỗi trên, vì vậy tôi không chắc nó có liên quan, nhưng tôi sẽ đăng nó anyway. Nếu tôi đính kèm với Trợ lý gỡ lỗi được quản lý và làm mới một nhóm, tôi cuối cùng nhận được:
Managed Debugging Assistant 'StreamWriterBufferedDataLost' has detected a problem in 'C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.EXE'.
Additional Information: A StreamWriter was not closed and all buffered data within that StreamWriter was not flushed to the underlying stream. (This was detected when the StreamWriter was finalized with data in its buffer.) A portion of the data was lost. Consider one of calling Close(), Flush(), setting the StreamWriter's AutoFlush property to true, or allocating the StreamWriter with a "using" statement. Stream type: System.Web.HttpResponseStream
File name: <unknown>
Allocated from:
at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.IO.StreamWriter.Init(Stream stream, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(Stream stream, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(Stream stream, Encoding encoding)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
at System.Web.Services.Protocols.SyncSessionlessHandler.ProcessRequest(HttpContext context)
at System.Web.Script.Services.ScriptHandlerFactory.HandlerWrapper.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
at System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(Exception error)
at System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
at System.Web.HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)
at System.Web.HttpRuntime.ProcessRequest(HttpWorkerRequest wr)
at Microsoft.VisualStudio.WebHost.Request.Process()
at Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn)
Tôi không chắc chắn nó có liên quan ... có thể chỉ là luồng lỗi.
Chỉnh sửa # 6:
OK, thêm thông tin. Tôi đã sử dụng bài đăng blog của Scott Hanselman here để tham gia hội thảo được tạo. Nó chỉ ra rằng mặc dù XmlInclude, các hội đồng được tạo ra KHÔNG có một tham chiếu đến các loại trong nó, vì vậy đây chắc chắn là một lỗi trong .NET. Tôi đang cố gắng để theo dõi những gì gây nên nó, nhưng một cái gì đó trong bất cứ điều gì tạo ra các hội đồng đầu ra (sgen?) Là không.
Chỉnh sửa # 7:
FYI cho bất cứ ai sau này, tôi đã gửi một báo cáo lỗi để MS:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=523253
Ngoài ra, cùng một mã chính xác được cập nhật trên 2 máy chủ khác nhau - một máy có thể hoạt động, máy còn lại có thể không phải là một crap chụp hoàn chỉnh. – jvenema
Bạn có thể đăng mã gây ra lỗi không? Bạn nên cố gắng tách biệt lỗi thành trường hợp đơn giản nhất có thể. – empi
Tôi không thể, đó là điều ... cùng một mã hoạt động trên một máy có thể hoạt động trên một máy khác, và có thể không, không có lời nói. Theo như tôi có thể nói, nó liên quan đến một số loại bộ nhớ đệm IIS. – jvenema