Occasional Exception when calling a method in wcf client proxy

0

Sometimes, on my xp machines, I get an exception when calling a method in my auto-generated client proxy. I told the debugger to stop on all clr exceptions. Now sometimes when I call the following:

public MyStuff.Entities.Package GetPackageById(System.Guid sessionId, int packageId)
    {
        return base.Channel.GetPackageById(sessionId, packageId);
    }

I first get an InvalidOperationException: Collection was modified... Pressing F10 results in a FileLoadException with the following messge:

Could not load file or assembly 'System.Runtime.Serialization.resources, Version=4.0.0.0, Culture=de-DE, PublicKeyToken=b77a5c561934e089' or one of its dependencies. An operation is not legal in the current state. (Exception from HRESULT: 0x80131509)

I'm sure the service didn't throw an exception because it would show up as a FaultException. Since it's an InvalidOperationException that's being thrown when calling base.Channel.GetPackageById(sessionId, packageId) I assume it's not directly my fault?

I'm slowly running out of ideas what I could try to eliminate or work around this exception.

It never happened when using my developer machine with windows 7 and .NET 4.5 installed on it. On XP this will happen 1 out of 4 times approximately.

GetPackageById on service side looks like this:

public Package GetPackageById(Guid sessionId, int packageId)
        {
            try
            {
                return DataProvider.Provider.GetPackagesByKey(packageId,null);
            }
            catch (Exception ex)
            {
                throw new FaultException<MySericeFault>(new MySericeFault(ex));
            }                        
        }

The Package Class looks like this:

    [DataContract(IsReference = true)]
    [KnownType(typeof(MyApp.Entities.MachinePackage))]
    public partial class Package: INotifyPropertyChanged
    {
    private DateTime? _outDate;
    [DataMember]
    public DateTime? OutDate
    {
        get { return _outDate; }
        set
        {
            if (_outDate != value)
            {
                _outDate = value;
                OnPropertyChanged("OutDate");
            }
        }
    }

    private int _productId;
    [DataMember]
    public int ProductId
    {
        get { return _productId; }
        set
        {
            if (_productId != value)
            {
                _productId = value;
                OnPropertyChanged("ProductId");
            }
        }
    }
    protected virtual void OnPropertyChanged(String propertyName)
    {
        if (_propertyChanged != null)
        {
            _propertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
    {
        add { _propertyChanged += value; } 
        remove { _propertyChanged -= value; }
    }
    private event PropertyChangedEventHandler _propertyChanged;
    }
c#
.net
wcf
asked on Stack Overflow Feb 19, 2013 by Steven S. • edited Feb 19, 2013 by Steven S.

1 Answer

2

This is more of an experiment but too big to put as a comment!

Try creating a new operation contract that performs this code:

Service:

public Package GetPackageByIdTest(Guid sessionId, int packageId)
{
    return new Package { ProductId = packageId, OutDate = DateTime.Now };
}

Then create a console application that references your service and write something like this:

Client:

static void Main(string[] args)
{
    for (int tester = 0; tester < 2000; tester++)
    {
        using (var service = new ConsoleApplication1.ServiceReference1.Service1Client())
        {
            Package result = service.GetPackageByIdTest(Guid.NewGuid(), tester);
            Console.WriteLine(result.ProductId);
        }
    }

    Console.ReadKey();
    return;
}

Then, try running that on one of the known XP machines that fails and see if you get the same issue. If not it would suggest there is something going a miss in your DataProvider.Provider.GetPackagesByKey(...) method.

answered on Stack Overflow Feb 19, 2013 by Belogix

User contributions licensed under CC BY-SA 3.0