GaboG

Hello, I'm trying to access the CustomAttributeData of a class that has the WebService attribute defined.

If the WebService attribute has a Namespace parameter + any of the other WebSercice parameters defined (Name or Description), it throws a CustomAttributeFormatException "Binary format of the specified custom attribute was invalid." exception.

If the WebService attribute has only the Namespace parameter defined, it works.

If the WebService attribute has does not have the Namespace parameter defined, it works.

The code bellow reproduces the problem, does anybody know if there's a workaround or a hot fix for this

Thanks

Gabo

-------

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Web.Services;

namespace WSAttrExeption
{
internal class Program
{
private static void Main()
{
try
{
IList<CustomAttributeData> cda;
cda = CustomAttributeData.GetCustomAttributes(typeof(Works));
Console.WriteLine(cda.Count);

cda = CustomAttributeData.GetCustomAttributes(typeof(GeneratesError));
Console.WriteLine(cda.Count);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}

[WebService(Namespace = "http://mynamespace.com")]
public class Works
{}

[WebService(Namespace = "http://mynamespace.com", Name = "blah")]
public class GeneratesError
{}
}



Re: .NET Base Class Library CustomAttributeData.GetCustomAttributes throws exception when type has a WebService attribute

Peter Ritchie

This post is off topic for the Visual C# Language forum and has to do with Reflection. Moving to the .NET Base Class Library forum.




Re: .NET Base Class Library CustomAttributeData.GetCustomAttributes throws exception when type has a WebService attribute

Mattias Sjogren

Seems like a genuine bug, and a weird one too. If you haven't already, I suggest you post a bug report at http://connect.microsoft.com/VisualStudio/feedback/

As for a workaround, unelss you need to use the CustomAttributeData class, you can call System.Type.GetCustomAttributes() instead.






Re: .NET Base Class Library CustomAttributeData.GetCustomAttributes throws exception when type has a WebService attribute

Stan Dvoychenko

The status of the bug submitted is closed (Fixed) here https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx FeedbackID=161522

In course of my work now, I'm trying to reproduce the error and can't do it.

Was my .NET 2.0 patched somehow by ongoing MS updates

Should we expect to see the problem above if we use CustomAttributeData and have a fresh install of .NET 2.0 redistributable





Re: .NET Base Class Library CustomAttributeData.GetCustomAttributes throws exception when type has a WebService attribute

Peter Ritchie

Yes, there was a security update that was released recently that had some various other fixes. If you've downloaded and installed .NET 3.5 Beta 2, or Visual Studio 2008 Beta 2; you've also installed .NET 2.0 Service Pack 1 beta.






Re: .NET Base Class Library CustomAttributeData.GetCustomAttributes throws exception when type has a WebService attribute

MarkPollack

Hi,

Apologies up front if this is off topic, but where can we find out information when .NET 2.0 Service Pack 1 will go final

Thanks for the info.

Cheers,

Mark





Re: .NET Base Class Library CustomAttributeData.GetCustomAttributes throws exception when type has a WebService attribute

Peter Ritchie

I haven't seen any formal announcement of dates. You might see that sort of announcement here: http://msdn2.microsoft.com/en-us/netframework/aa731542.aspx

I'd speculate that .NET Framework 2.0 Service Pack 1 will be released in February or March.