.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Post New Web Links

InvalidCastException - IMetadataExchange

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :SharePoint

I can't seem to get MetaDataExchange working with my custom token issuer.   


VS2010 Add Service Reference to https://localhost/sts/sts.svc


Notice first chance exception on service host activation:


A first chance exception of type 'System.InvalidCastException' occurred in System.ServiceModel.dll

Additional information: Unable to cast object of type 'Microsoft.IdentityModel.Protocols.WSTrust.WSTrustServiceContract' to type 'System.ServiceModel.Description.IMetadataExchange'.







        <!-- default behavior because name attribute is omitted -->        

        <behavior name="TokenIssuerServiceBehavior">


          The serviceMetadata behavior allows one to enable metadata (e.g. WSDL, Policy) publishing.

          This configuration enables publishing of such data over HTTP GET.


View Complete Post

More Related Resource Links

Databind on Gridview throwing System.InvalidCastException. Specific Cast Not Valid

Hello, I am working on a web app where when the user enters data into a text box and presses a filter radio button it should filter the Gridview on the page to the criteria entered.  I have done this before in previous applications with the same code listed below, but for some reason I am now getting the InvalidCastExeption error.  Any help would be appreciated, the source database is SQL and the data field is set to nvarchar and I am using a string to compare as you will see in the code.  I am just unsure why this worked in the past and is not working in this scenario. Thanks, Pete protected void filterLName_CheckedChanged(object sender, EventArgs e) { SHCDataContext existingCustomers = new SHCDataContext(); var filterExistingCustomers = existingCustomers.Customers.Where(c => c.custLastName.Contains(lNameTB.Text.ToString())); displayCustGV.DataSource = null; displayCustGV.DataSourceID = null; displayCustGV.DataSource = filterExistingCustomers; displayCustGV.DataBind(); }   Here is the stack trace....  Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.I

InvalidCastException when calling JavaScript from C# control using a second thread.

Original Issue: I need to be able to call functions in the JavaScript of an HTML page (not ASP.NET) from a C# object embedded in that page.  The c# object has to be .NET 2 level. So I created a C# DLL assembly in VS 2010 which contains a class called NoUIControlClass. set the target framework to .NET 2.0 and made sure to check "Make assembly COM-Visible".  I also signed the assembly so it would have a strong name so I could install it in the GAC.  So far so good. Here is the batch file I run after the project is built to register the control and place it into the GAC: copy "C:\Users\x\Documents\Visual Studio 2010\Projects\NoUIControl\NoUIControl\bin\Debug\NoUIControl.dll" C:\Exploration\NoUIControl C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm NoUIControl.dll /unregister C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm NoUIControl.dll NoUIControl.dll C:\"Program Files (x86)"\"Microsoft SDKs"\Windows\v7.0A\Bin\gacutil.exe /u NoUIControl.dll C:\"Program Files (x86)"\"Microsoft SDKs"\Windows\v7.0A\Bin\gacutil.exe /i NoUIControl.dll This works and all is good.  Next I've turned the security level in IE all the way down for intranet and trusted sites.  Just to make sure that doesn't get in the way.  Here is the HTML file I serve from the web server. <html> <head

Help with an InvalidCastException with Windows Media Services on Windows Server 2008 R2

Hi, I developed an application that utilizes content from Windows Media Services. The entire application was written in C# on a Windows Server 2008 x86 environment using the interop assemblies provided by Microsoft. Everything works fine, except when I try to run the application on a 64-bit machine. When I run the application on the 64-bit machine, I get the following error: Unable to cast COM object of type 'Microsoft.WindowsMediaServices.Interop.WMSServerClass' to interface type 'Microsoft.WindowsMediaServices.Interop.IWMSServer'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{845FB958-4279-11D2-BF23-00805FBE84A6}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)). I tried looking for an updated interop assembly, but couldn't locate anything newer than the one that I was already using. Does anyone know how to get over this hurdle?

InvalidCastException was unhandled: No such interface exists

Hi All I've been trying for the last few days to get an XMLBulkLoader working in C#.NET, code below [STAThread] private void btnLoadXML_Click(object sender, EventArgs e) { SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class objXBL = new SQLXMLBULKLOADLib.SQLXMLBulkLoad4Class(); objXBL.ConnectionString = @"Provider=sqloledb;server=DUBW00000243\SQL2005;database=SepaDD;User ID='tony';Password='metallica'"; objXBL.ErrorLogFile = "XMLError.log"; objXBL.KeepIdentity = false; objXBL.Execute(@"C:\xml\SampleSchema.xsd", @"C:\xml\SampleXMLData.xml"); } It's throwing back at error at the following line - objXBL.Execute(@"C:\xml\SampleSchema.xsd", @"C:\xml\SampleXMLData.xml"); I've been reading a lot about specifying STAThread as C# uses Multi threading by default as opposed to VB which uses Single Threading by default. This is not making any difference for me. I've got a simple XML / XSD and I want this to load the data from my sample xml data file into the database... Can anyone help, please? Thanks in advance Tony.

IMetadataExchange issue in WCF


Hello everyone,

I am using VSTS 2010 + C# + .Net 4.0 + IIS 7.5 + Windows 7. I am following MSDN sample here without any modifications, http://msdn.microsoft.com/en-us/library/ms733766.aspx

When I open the service.svc file (in IIS manager, right click the svc file and select browse) in IIS, there is an error like this, any ideas what is wrong?

in the service list CalculatorService not find the protocol name "IMetadataExchange". Add ServiceMetadataBehavior to the configuration file or directly add to the ServiceHost

thanks in advance,


InvalidCastException error



I am encountering the error "Unable to cast object of type 'System.Data.Linq.EntitySet`1[GRIPS.ActivityMember]' to type 'GRIPS.ActivityMember'"

on the bolded script below: 

namespace GRIPS
    public partial class ActivityMember_EditField : System.Web.DynamicData.FieldTemplateUserControl

        protected override void OnDataBinding(EventArgs e)
            object val = FieldValue;
            ActivityMember myActivityMemberInfo = (ActivityMember)FieldValue;
            if (myActivityMemberInfo != null)
                ActivityMemberId.Value = myActivityMemberInfo.ActivityMemberId.ToString();
                ActivityId.Value = myActivityMemberInfo.ActivityId.ToS

The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by t


trying to include IMetadataExchange contract and setting httpgetenabled = true, but still could not found in list error,


ServiceHostWCF's app.config
<?xml version="1.0" encoding="utf-8" ?>
                <behavior name="NewBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                <binding name="NewBinding0" />
            <service name="WcfServiceLibrary1.Service1">
                <endpoint address="ws" binding="basicHttpBinding" bindingConfiguration=""
                    contract="WcfServiceLibrary1.IService1" />
                        <add baseAddress="http://localhost:8731/Service1" />
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend