locked
Deploy error with CLR trigger - cannot store static data RRS feed

  • Question

  • I am trying to deploy a CLR trigger and I am getting the error:

    . . . . .Amazon.MWS.Server.sql(37-37): Deploy error SQL01268: .Net SqlClient Data Provider: Msg 6212, Level 16, State 1, Line 1 CREATE ASSEMBLY failed because method 'Clean' on type 'MarketplaceWebServiceOrders.MarketplaceWebServiceOrdersConfig'  in safe assembly 'Amazon.MWS.Server' is storing to a static field. Storing to a static field is not allowed in safe assemblies.

    If I look at the 'Clean' method I see:

            /// <summary>
            /// Replace all whitespace characters by a single space.
            /// </summary>
            private static string Clean(string s)
            {
                // matched character sequences are passed to a MatchEvaluator
                // delegate. The returned string from the delegate replaces
                // the matched sequence.
                return Regex.Replace(s, @" {2,}|\s", delegate(Match m)
                {
                    return " ";
                });
            }
    

    I guess I am unclear what the error is telling me. What does static data have to do with a 'safe' assembly? Any suggestions on how I might work around this?

    Thank you.


    Kevin Burton

    • Moved by Alan_chen Monday, February 27, 2012 3:03 AM (From:ADO.NET Managed Providers)
    Friday, February 24, 2012 7:52 PM

Answers

  • Kevin is correct (in the previous message) that you can’t have a mutable static variable in a safe assembly. But, the Clean method that you posted doesn’t do that (I can put it (your Clean method) in an assembly and call it and still catalog the assembly containing that code as SAFE), so it must be how you’re using it. Try storing the results of Clean into an instance variable rather than a static.
     
    Cheers,
    Bob
    • Marked as answer by KevinBurton Wednesday, March 7, 2012 9:55 PM
    Monday, February 27, 2012 6:43 AM

All replies

  • Hello Kevin,

    MSDN documention (Under Remarks section) indicates that The assembly should not contain any static data members in its classes unless they are marked as read-only.


    KSG

    Sunday, February 26, 2012 7:16 PM
  • Kevin is correct (in the previous message) that you can’t have a mutable static variable in a safe assembly. But, the Clean method that you posted doesn’t do that (I can put it (your Clean method) in an assembly and call it and still catalog the assembly containing that code as SAFE), so it must be how you’re using it. Try storing the results of Clean into an instance variable rather than a static.
     
    Cheers,
    Bob
    • Marked as answer by KevinBurton Wednesday, March 7, 2012 9:55 PM
    Monday, February 27, 2012 6:43 AM