CSLA 4.5.2 beta and async DataPortal_Fetch with Silverlight5

CSLA 4.5.2 beta and async DataPortal_Fetch with Silverlight5

Old forum URL: forums.lhotka.net/forums/t/11604.aspx

Curelom posted on Thursday, September 27, 2012

I'm trying out the new beta and I'm getting a DataPortal.Fetch not found.  What could I be doing wrong?

I'm calling my BL (BannerList) with





obj = await BannerList.GetAll();



In my BL I'm calling below

 public static async Task<BannerList> GetAll() {




var task = await DataPortal.FetchAsync<BannerList>();




return task;


My DataPortal Fetch looks like this


protected async Task DataPortal_Fetch(){




  using (var ctx = Csla.Data.ObjectContextManager<CmsLibrary.Data.CmsModelContainer>.GetManager(CmsModel.CmsModelContainerDatabase .Name)) {




   var data = ctx.ObjectContext.Banners.AsEnumerable();






JonnyBee replied on Thursday, September 27, 2012

Try returning Task<BannerList> from DataPortal_Fetch

RockfordLhotka replied on Thursday, September 27, 2012

I don't see a problem with the code, other than you'll get a compile warning because you have an async method without using an await statement inside. Given your current code there is no reason for the DayaPortal_Fetch method to be async...

What are the client and server platforms?

RockfordLhotka replied on Thursday, September 27, 2012

A nitpick, but I thought I'd point it out anyway. When you await FetchAsync you don't get back a task, you get back a T. In other words, you get back the business object you are requesting.

Curelom replied on Friday, September 28, 2012

Please nitpick Wink  Get's me better code.

I've found the one problem was me not setting ProxyTypeName.  Now I get a different error.  Object reference not set to an instance of an object.

I'm digging through the Data Portal eBook to make sure I've got all my configs right.


RockfordLhotka replied on Friday, September 28, 2012

Well there is that...

The configuration settings are changed quite a lot for SL in 4.5.2. I talked about this somewhat in a recent blog post.

Most notably, all namespaces like Csla.Server.Hosts.Silverlight are now Csla.Server.Hosts.Mobile - replace "Silverlight" with "Mobile" on client and server types.

bill.mybiz replied on Sunday, November 25, 2012

Yooooooooooo Curelom, did you ever resolve this? I also am having the same problem. I've migrated my SL 4/.Net 4.0 code to SL 5/.Net 4.5. I've spent several days doing a ton of the async/await changes, including the one mentioned by Rocky with the namespace changes. Also, btw for anyone else out there, I had to take out the generic in WcfProxy definition used in the compressed proxy, so CompressedProxy/*<T>*/ : Csla.DataPortalClient.WcfProxy//<T>.

So anyway, I've finally gotten my code to compile with the new awesomeness that is async/await combined with Csla's awesomeness!!! Awww yeah, that's a whole lotta awesome. And now, when I'm sending the async login call with the new async stuff, however, it's not reaching the server. It's giving me the classic "Object reference not set to an instance of an object." which I thought had to do with the config of the portal. Is there anything else you did to change the config in your migration?


Bill Raiford

bill.mybiz replied on Sunday, November 25, 2012

Thought I'd throw in the code that pertains to this as well. This code used to work with the callbacks. Perhaps it is an IIS configuration problem? (I've moved also from Vista 32-bit to Win8 64-bit if that makes a difference.) I'm still chugging away at it myself, but I thought if you got any headway, that you might help this mayn out. Thanks!

(all code at: https://github.com/bill-mybiz/LearnLanguages)

UserIdentity retIdentity = null;
      var criteria = new UsernameCriteria(username, clearUnsaltedPassword);
        retIdentity = await DataPortal.FetchAsync<UserIdentity>(criteria);
      catch (Exception ex)
        retIdentity = null;


And here is the data portal code:

private void DataPortal_Fetch(UsernameCriteria criteria)
      AuthenticationType = DalResources.AuthenticationTypeString;
      using (var dalManager = DataAccess.DalFactory.GetDalManager())
        var dal = dalManager.GetProvider<IUserDal>();

        var verifyResult = dal.VerifyUser(criteria.Username, criteria.Password);
        if (!verifyResult.IsSuccess)
          Exception error = verifyResult.GetExceptionFromInfo();
          if (error != null)
            throw error;
            throw new FetchFailedException(verifyResult.Msg);
        bool? userIsVerified = verifyResult.Obj;
        if (userIsVerified == null)
          userIsVerified = false;

        if (userIsVerified == true)
          LoadUserData(criteria.Username, dal);

bill.mybiz replied on Sunday, November 25, 2012

Just an update. I've determined that I didn't update my web.config and SlPortal.svc files appropriately in the host project. Correcting that, using the 4.5 ProjectTracker's versions of these files as guidance, I've gotten past the not set to an instance error message and now I'm in it with a different one that has me stumbling as well. I'm just posting for anyone else also migrating from 4 to 4.5 as well.

The current error I'm getting is Csla.DataPortalException was caught
  Message=Non-negative number required.
Parameter name: count
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
       at LearnLanguages.Business.Security.UserIdentity.<GetUserIdentityAsync>d__0.MoveNext()

That's all that copy exception detail to clipboard copies nowadays. I don't know why it doesn't include the inner exception anymore. Maybe a config setting somewhere that I couldn't find...hmmm Stick out tongue. Anyyyyyyyway. Non-negative number required. Seems to be related to await. This still is not reaching the server side of things, so I'm stinking it's still a configuration problem.


PS: Here is some of the inner exception detail:

   at System.IO.BinaryReader.ReadChars(Int32 count)
   at Csla.Serialization.Mobile.CslaBinaryReader.ReadObject(BinaryReader reader) in c:\Users\Rockford\Documents\Visual Studio 2012\Projects\csla\trunk\Source\Csla\Serialization\Mobile\CslaBinaryReader.cs:line 123
   at Csla.Serialization.Mobile.CslaBinaryReader.Read(Stream serializationStream) in c:\Users\Rockford\Documents\Visual Studio 2012\Projects\csla\trunk\Source\Csla\Serialization\Mobile\CslaBinaryReader.cs:line 46
   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Stream serializationStream) in c:\Users\Rockford\Documents\Visual Studio 2012\Projects\csla\trunk\Source\Csla\Serialization\Mobile\MobileFormatter.cs:line 216
   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Byte[] data) in c:\Users\Rockford\Documents\Visual Studio 2012\Projects\csla\trunk\Source\Csla\Serialization\Mobile\MobileFormatter.cs:line 375
   at Csla.Server.Hosts.Mobile.WcfPortal.Fetch(CriteriaRequest request) in c:\Users\Rockford\Documents\Visual Studio 2012\Projects\csla\trunk\Source\Csla\Server\Hosts\Mobile\WcfPortal.cs:line 97

bill.mybiz replied on Monday, November 26, 2012

One more piece of info: When I change between Local IIS Web server and Visual Studio Development Server, I get the same error: Non-negative number required. Parameter name count. So, maybe it isn't IIS.

I also tried removing all references to csla and async targeting via dlls, and instead using nuget manager in order to debug inside csla. It turns out it is actually being thrown in System.ServiceModel.Activation.HostedHttpTransportManager in the HttpContextReceived method at the line:

IAsyncResult httpContextReceivedResult = listener.BeginHttpContextReceived(hostedContext,


I can't read what any of the values are, as they are being optimized out of scope of the debugger, but the error is occurring here, which again makes me think it's some kind of wcf config error.

Does anyone out there in the whole wide web of worlds have any clue what's up here? Curelom, did you find an answer for your problem? I'm banging my head against the wall on this one. Crying

Curelom replied on Tuesday, November 27, 2012

Sorry for the late reply.  Wasn't able to log in to this site.  I was finally able to get in by using Firefox instead of IE10. 

All I did was change my configurations on the host and server down to the most basic configuration possible and it worked.  Been working on other projects lately and haven't been able to look into this further.

bill.mybiz replied on Tuesday, November 27, 2012

Well, I renamed my WcfPortal.svc and SlPortal.svc files, as well as my web.config. I then copied those files from the ProjectTracker sample, only editing the Dal implementation values in the appSettings section. I have a mock Dal, so I didn't even change the connection string settings. I renamed (removed from the equation) my ServiceReferences.ClientConfig, which I had from what I remember because of something to do with Wcf failing for security reasons (though I don't remember offhand what those were, maybe something to do with allowing cross-site scripting). Anyway, I took that out at the SL side, and I ran the program again. Same error at the same call as mentioned previously.

At this point, I'm going to start a new project, and see if I can get the simplest Csla app going from scratch. I'm avoiding upgrading from anything vs 2010/net 4.0/sl 4 project, as I already have my own barebones simple app at my github site (for an example for anyone wanting to mix csla and caliburn). So, I'm going to do that again, only now with Windows 8, Csla 4.5, SL 5, .NET 4.5. If it works, I'll probably then throw Caliburn Micro 1.3.1 into the mix.

Any info about this error would be much appreciated in the meantime.

And thanks for your reply Curelom! I know it's tough working on lots of projects at once. I code in mostly Delphi at work, then I come home and work on my baby ;)

RockfordLhotka replied on Tuesday, November 27, 2012

Bill, I assume you are not still using the beta code, but are using the 4.5.10 release code?

There were a bunch of bugs in the beta code, so if you are still using that then there's little I can say but to upgrade to the release version.

I think your idea of starting with a simple app is smart. That should help eliminate environmental or basic configuration/install issues.

The SampleApp and SimpleNTier and ProjectTracker apps all have Silverlight clients calling app servers, so I'm pretty confident that the data portal works. There are a couple known bugs that will be fixed in the next release, but they don't have the effects you are describing.

bill.mybiz replied on Thursday, November 29, 2012

Quick post before bed:

In app startup (MefBootstrapper for myself, using Caliburn), I had to add the following line:

Csla.ApplicationContext.DataPortalProxy =

Without this line, it gives me the horrific Non-Negative Number of Voodoo Required. I didn't used to have this line in there, and I don't really know what it does. I'm really tired (as I am a lot of time working on this project hehe), so I'm gonna look at this tomorrow some more. But for anyone else out there migrating up to the 4.5 async/await stuff with the aforementioned error of doom: try adding this and see if it helps.

Bill Raiford

RockfordLhotka replied on Tuesday, November 27, 2012

(the latest IE10 update does appear to have stopped working with the forum site - sadly there's not a lot I can do because the forum software is old and now unsupported - so I think in 2013 I'll have to look at migrating us all to some new forum software...)

Copyright (c) Marimer LLC