none
Global Values that access a database Fail in VS2012 and VS2013 Preview

    Question

  • Hi, I have an issue with Global Values that access the database, in VS2012 and VS2013 Preview they fail with the following error:

    An exception of type 'System.TypeInitializationException' occurred in Application.Server.dll but was not handled in user code

    Additional information: The type initializer for 'LightSwitchApplication.GlobalValues' threw an exception.

    I noticed that this works for the client as calculated parameters that display on the client are fine, however when it's called on the server that is when I get the error. It gets called on the server when I run a DevExpress XtraReports for LightSwitch repor, which get executed on the server.

    My code which work fine in LightSwitch 2011 :) I am assuming that something changed in VS2012 that I missed.

    using System;
    
    namespace LightSwitchApplication
    {
        public static class GlobalValues
        {
            static GlobalValues()
            {
                var DW = new DataWorkspace();
                var myCompany = DW.AccountsData.MyCompanyDetail();
    
                if (myCompany != null)
                    _CurrencyFormat = myCompany.CurrencyFormatString;
                else
                    _CurrencyFormat = "{0}#,#.00#;({0}#,#.00#)";
            }
    
            private static String _CurrencyFormat;
            public static String CurrencyFormat
            {
                get { return _CurrencyFormat; }
            }
        }
    }


    See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.

    Friday, July 12, 2013 2:53 PM

Answers

  • I took it offline with Stephen and found out that, basically, due to some changes in transaction handling in LightSwitch 2012+ the same pattern of calls (made by the DevExpress reporting engine) that was working in LS 2011 now results in an attempt to elevate the local transaction (that LS creates for every submit operation) into a distributed transaction, requiring DTC service to be running.

    The simplest solution here is to just make sure that DTC service is running on the machine that the application is deployed to (I mean middle tier).

    Thursday, July 18, 2013 11:46 PM

All replies

  • Stephen, can you set a breakpoint in the static constructor of the GlobalValues class and report what the actual exception thrown from the constructor is?
    Sunday, July 14, 2013 3:28 AM
  • Hi Karol, I tried that and It never breaks there I put a break point on the line:

    var myCompany = DW.AccountsData.MyCompanyDetail();

    it breaks there I did F10 to step through the code and it does not step to the next line of code it just error at the spot where I am using it :( see where it calls GlobalValues.CurrencyFormat below.

    partial void DisplayHourlyRate_Compute(ref string result)
    {
        if (this.Department != null)
            result = this.HourlyRate.ToString(String.Format(GlobalValues.CurrencyFormat, this.Department.Customer.Currency.Symbol));
        else
            result = "0.00";
    }

    Exceptions

    {"The type initializer for 'LightSwitchApplication.GlobalValues' threw an exception."}

    {"The expression is not supported.   Expression: Convert(value(LightSwitchApplication.AccountsDataService).MyCompanyDetail())"}

    {"Exception has been thrown by the target of an invocation."}

    {"The underlying provider failed on Open."}

    {"MSDTC on server 'SMAUGH\\SQL2012' is unavailable."}

    Below is a screen shot of the exceptions "unwrapped" hope that helps.

    Looking at the most inner exception {"MSDTC on server 'SMAUGH\\SQL2012' is unavailable."} I would have expected this to happen on the client not the server as the database is on the same computed (at the moment my dev PC)?

    Note the static constructor gets called once for the client side and then when I run the report (XtraReports for LightSwitch) which is run on the server it gets called again and this as you suspected is where I get the issue.




    See my blog C# Bits | Twitter @sjnaughton Always seeking an elegant solution.

    Sunday, July 14, 2013 10:08 AM
  • I took it offline with Stephen and found out that, basically, due to some changes in transaction handling in LightSwitch 2012+ the same pattern of calls (made by the DevExpress reporting engine) that was working in LS 2011 now results in an attempt to elevate the local transaction (that LS creates for every submit operation) into a distributed transaction, requiring DTC service to be running.

    The simplest solution here is to just make sure that DTC service is running on the machine that the application is deployed to (I mean middle tier).

    Thursday, July 18, 2013 11:46 PM