assembly does not allow partially trusted callers

  • I am trying to send an xml message via MSMQ from a stored procedure.

    I am passing an XmlDocument\string\etc to a Message and am receiving errors.

    First I resolved this:

    http://kbalertz.com/913668/Error-message-common-language-runtime-object-Server-dynamically-generated-serialization.aspx,

    only to start seeing this: http://www.kodyaz.com/blogs/software_development_blog/archive/2006/10/15/455.aspx

    and can't seem to get past the "assembly does not allow ..." issue.

    This method works via web page, but this has to be a SQL Server 2005 security issue, because that is the only place it is failing.

    I have been looking everywhere and have tried at least 20 different iterations.

    I created (sgen) the serialized version, my assembly is strong named, the XmlSerializer is strong named, the assembly property AllowPartiallyTrustedCallers is set.

    My db is set trustworthy on

    assemblies Permission set: Safe - primary and XmlSerializer

    What else can I do, how else can I gather more info to help me troubleshoot?

    -----------------------------------------------------------------

    Sample code trying to send xml message to MSMQ from stored procedure:

    public static void Send(SqlString queue, SqlString msg)

    {

    XmlDocument _xmlDoc;

    XmlNode _xmlNode;

    XmlElement _xmlElement1;

    XmlElement _xmlElement2;

    XmlText _xmlText;

    _xmlDoc = new XmlDocument();

    _xmlNode = _xmlDoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");

    _xmlDoc.AppendChild(_xmlNode);

    _xmlElement1 = _xmlDoc.CreateElement("", "ROOT", "");

    _xmlText = _xmlDoc.CreateTextNode("");

    _xmlElement1.AppendChild(_xmlText);

    _xmlDoc.AppendChild(_xmlElement1);

    _xmlElement2 = _xmlDoc.CreateElement("", "PLCID", "");

    _xmlText = _xmlDoc.CreateTextNode("1");

    _xmlElement2.AppendChild(_xmlText);

    _xmlDoc.ChildNodes.Item(1).AppendChild(_xmlElement2);

    using (MessageQueue msgQueue = new MessageQueue(queue.ToString(), QueueAccessMode.Send))

    {

    //// version1

    msgQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });

    msgQueue.Send(msg.Value);

    //// version1.1

    //msgQueue.Formatter = new XmlMessageFormatter(new System.Type[] { typeof(XmlDocument) });

    //msgQueue.Send(_xmlDoc);

    //version2

    //XmlNode node = _xmlDoc;

    //XmlSerializer XS = new XmlSerializer(typeof(XmlNode));

    //MemoryStream MS = new MemoryStream();

    //XS.Serialize(MS, node);

    //string str = System.Text.Encoding.ASCII.GetString(MS.GetBuffer());

    //string label = string.Format("Sent at {0}", DateTime.Now);

    //msgQueue.Send(str, label);

    }

    }

    Sample database code:

    alter database test set trustworthy on

    create assembly Messaging

    authorization dbo

    from 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Messaging.dll'

    with permission_set = unsafe

    go

    create assembly [nsSqlMsmq] from 'C:\tempsSqlMsmq.dll'

    create assembly [nsSqlMsmq.XmlSerializers.dll] from 'C:\tempsSqlMsmq.XmlSerializers.dll'

    -- Create procedures

    create PROCEDURE uspMSMQSend

    @queue nvarchar(200),

    @msg nvarchar(MAX)

    AS EXTERNAL NAME nsSqlMsmq.[nsSqlMsmq.clsSqlMsmq].Send

    GO

    --EXEC uspMSMQSend 'server-name\private$\queuename', '1'

  • Please don't cross post. It just wastes peoples time and fragments replies.

    No replies to this thread please. Direct replies to: http://www.sqlservercentral.com/Forums/Topic705013-359-1.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply