There are several ways of fixing this problem and it usually involves editing your machine.config, web.config or app.config file. One of the possibilities that might have raised this error is a bug that you’ll encounter when uninstalling Microsoft Azure SDK. Apparently when you install the Microsoft Azure SDK, it adds a few lines to your machine.config file. However when you uninstall it, it doesn’t revert the changes causing your machine.config to refer to unavailable libraries.

So in order to fix this error, you’ll have to comment/delete these few lines from your machine.config file.

<!-- Under <behaviorExtensions> -->
<add name="connectionStatusBehavior" type="Microsoft.ServiceBus.Configuration.ConnectionStatusElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="transportClientEndpointBehavior" type="Microsoft.ServiceBus.Configuration.TransportClientEndpointBehaviorElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="serviceRegistrySettings" type="Microsoft.ServiceBus.Configuration.ServiceRegistrySettingsElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<!-- Under <bindingElementExtensions> -->
<add name="tcpRelayTransport" type="Microsoft.ServiceBus.Configuration.TcpRelayTransportElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="httpRelayTransport" type="Microsoft.ServiceBus.Configuration.HttpRelayTransportElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="httpsRelayTransport" type="Microsoft.ServiceBus.Configuration.HttpsRelayTransportElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="onewayRelayTransport" type="Microsoft.ServiceBus.Configuration.RelayedOnewayTransportElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<!-- Under <bindingExtensions> -->
<add name="basicHttpRelayBinding" type="Microsoft.ServiceBus.Configuration.BasicHttpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="webHttpRelayBinding" type="Microsoft.ServiceBus.Configuration.WebHttpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="ws2007HttpRelayBinding" type="Microsoft.ServiceBus.Configuration.WS2007HttpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="netTcpRelayBinding" type="Microsoft.ServiceBus.Configuration.NetTcpRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="netOnewayRelayBinding" type="Microsoft.ServiceBus.Configuration.NetOnewayRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="netEventRelayBinding" type="Microsoft.ServiceBus.Configuration.NetEventRelayBindingCollectionElement, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<!-- Under <client> -->
<endpoint address="" binding="netTcpRelayBinding" contract="IMetadataExchange"
    name="sb" />

<!-- Under <metadata><policyImporters> -->
<extension type="Microsoft.ServiceBus.Description.TcpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<extension type="Microsoft.ServiceBus.Description.HttpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<extension type="Microsoft.ServiceBus.Description.OnewayRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

<!-- Under <metadata><wsdlImporters> -->
<extension type="Microsoft.ServiceBus.Description.StandardRelayBindingImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<extension type="Microsoft.ServiceBus.Description.TcpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<extension type="Microsoft.ServiceBus.Description.HttpRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<extension type="Microsoft.ServiceBus.Description.OnewayRelayTransportBindingElementImporter, Microsoft.ServiceBus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
 

I was recently given a task to refactor and extract the XML Literals and here’s my solution, which isn’t the best, but it is good enough for now.

Let’s say you have this code:

Dim number1 As Integer = 5
Dim number2 As Integer = 10
Dim xml = <MyXml><%= number1 %><%= number2 %></MyXml>

Where you have an embedded variable using XML Literals within this block of XML. You want to extract that XML out to a file, instead of embed it into the language. Here’s a solution I came up with, and will definitely be thinking of how to solve this problem a little less “hack-ishly”.

<MyXml>{0}{1}</MyXml>

So I extracted out the XML and replaced all embedded XML Literal code with {0}..{1}..{n}. Or anything that’s unique for replacement.

Public Shared Function GetXml(ByVal number1 As Integer, ByVal number2 As Integer)
    Dim template = New StringBuilder(XElement.Load("myxml.xml").ToString())
    Return XElement.Parse( _
            template.Replace("{0}", number1) _
            .Replace("{1}", number2) _
            .ToString())
End Function

Then I read the xml file and spit it out as a string, replace all the {0}..{1}..{n} with the actual parameters. I was actually going to use String.Format (hence the chosen {0}..{1}..{n} replacement) but couldn’t seem to get it to work.

Dim number1 As Integer = 5
Dim number2 As Integer = 10
Dim xml = GetXml(number1, number2);

So all I do is just replace that entire block of XML Literal with a call to the method. That’s how you can refactor and extract out the XML Literals from Visual Basic .NET code. If you know of a better way to do this, please post a comment with your solution.

Note: Please mind my Visual Basic .NET code. It’s not my first language.

© 2009 - 2011 JustinLee.sg Suffusion theme by Sayontan Sinha
Stop SOPA!

SOPA breaks our internet freedom!
Any site can be shut down whether or not we've done anything wrong.

Stop SOPA!