Error while accessing DLL interface from Web Application - c#

I have made one windows Form application in C#. I have added one DLL reference in that application and called method of that DLL. Its working fine. But when I have made web application and added reference of same DLL and tried to run then I am getting error as
Unable to cast COM object of type 'XXXXX.XXXX' to interface type 'XXXXX.XXXX'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '{2DEEB1D7-0B44-4142-9E7B-07477781696C}' failed due to the following error: Bad variable type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE)).
The method in DLL, I am calling from web application as
m_SSCP.StartUp("FilePath", "value1", "value2", 6553703, 0, out return_code);
So if I am calling same function from Web application and Windows form application, Is there any difference between these two operation?
I tried to search on net but I am not getting any proper help.

Related

Custom HRESULT from COM component

Creating custom HRESULT has been covered here
Creating your own HRESULT?
Solution to above question is fine for c++ native clients, they can use the returned HRESULT to FormatMessage() and get error string, what about C# and JavaScript client? For discussion's sake let us forget FormatMessage() via PInvoke.
e.g. if a COM function returns E_ACCESSDENIED and C# client will receive it via nicely packaged exception, complete with error string and symbolic name(E_ACCESSDENIED)
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
It is understood system error codes have been mapped to .Net exceptions.
Questions is how to return an message compiler generated custom error codes packaged in HRESULT?
Is MAKE_HRESULT the answer?

C# simple device application is throwing Class not registered exception

I wrote a simple program to read barcode using Motorola mc5040 SDK
As soon as below code line gets executed
CCoreScanner cCoreScanner = new CCoreScanner();
Following exception gets thrown
exp.Message = "COM object with CLSID '{9F8D4F16-xxx-xxxx-98B3-xxxx}' cannot be created due to the following error: Class not registered ."
Any pointers how to resolve this ? I am running simple windows form with one button and a text box on actual Device running Windows CE.

The remote server returned an error: NotFound WCF Service

Windows Phone 8, Windows 8 + updates 64 bit, VS 2012. Running VS2012 as an admin
I have created a WCF service. Code on the service:
[OperationContract]
Object GetCustomersObject();
Implementation code
public Object GetCustomersObject()
{
object c = DataContext.Customers;
return c;
}
I then Add a New Website to my application and configure the Service.svc file to point to the contract etc. Run it in a web browser and can see the WSDL.
I then test it using the WCFTestClient utility but i can connect to all the methods except for the one above as it does not support an Object.
I now create a Win Phone 8 project and connect to the service i then get the error "An exception of type 'System.ServiceModel.CommunicationException' occurred in System.ServiceModel.ni.dll but was not handled in user code"
expanding the exception i notice the message is The remote server returned an error: NotFound.. I then follow the steps found at http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj684580(v=vs.105).aspx since i am running IIS under VS i dont follow instructions for anything else (that is i add an entry to the config as suggested and open the firewall port, delete the existing service and readd it after shutting down the IIS service).
I still get the same error. So i delete the service and re-add it using the IP, machine name and whichever ive used still gives the same error.
I have also tried to turn the Windows Firewall service off to eliminate it being a firewall issue and same problem remains.
Im lost as to what else i could try?
Sadly, "NotFound" does not mean that the service was actually not found. It's IIS' way to tell you "something failed".
Most likely, the failure occurs because you don't have a KnownType or ServiceKnownType attribute on your service or service interface although you need one.
The serializer of WCF is not omniscient. It looks at your function signature and serializes exactly that. Your signature says you return an object. Returning anything but null or new object() will irritate the serializer and make your service call fail. If you want to serialize something that is not a basic framework type and is not visible from the methods signature, you need to put a KnownType attribute with that type on your service class or a ServiceKnownType attribute on your interface to let the DataContractSerializer know what's coming.
Example:
[ServiceContract]
[ServiceKnownType(typeof(YourCustomer))]
public interface IYourService
{
[OperationContract]
Object GetCustomersObject();
}
You typically see a CommunicationException because the app can’t find the web service at localhost.
Here is the solution for the same it might work
https://msdn.microsoft.com/library/windows/apps/jj684580%28v=vs.105%29.aspx

Why does my call to a VB6 ActiveX DLL from C# app fail with "No such interface supported"?

I have a VB6 Active DLL that I'm trying to call from C#.
I've converted it using tblimp and imported it into VS 2010.
I then instantiate it using:
AppWebActiveX.Users appWebActiveX = new appWebActiveX.Users();
There's a Users interface and a UsersClass class when I look in the object browser.
Then I call:
bool isExistingUser = appWebActiveX.IsExistingUser("cat");
bool IsExisting(string) is a valid method, according to the object browser.
However, this returns:
Unable to cast COM object of type 'AppWebActiveX.UsersClass' to interface type 'AppWebActiveX._Users'. ... No such interface supported ...
The latest stack call is to System.StubHelpers.StubHelpers.GetCOMIPFromRCW.
I'm running the app on Windows Server 2003 Standard Edition (x86 - 32bit) and it's a 32-bit DLL. I'm making the call from a C# console app.
Any advice?
Turns out that I'd omitted the [STAThread] attribute from the main method.

C# COM server access from JScript

I have a COM server, implemented in C#. It exposes a class decorated like this:
[ComVisible(true)]
[ProgId("MyServer.MyClass")]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
I registered the DLL with "regasm /codebase MyServer". This server must be used from a WSC (a COM server implemented in JScript). Therefore I used the AutoDispatch interface.
When the WSC calls
o = new ActiveXObject("MyServer.MyClass");
I get the error "Automation serve can't create object".
I checked the registration of the COM server with this C++ program:
hr = ::CoInitialize(NULL);
hr = ::CLSIDFromProgID(L"MyServer.MyClass", &clsid);
hr = ::CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_IDispatch, (void**)&pObj);
and was able to create the object. All return values have been checked to be S_OK.
What is needed to make the COM server accessible for JScript?
If the problem is x64, see the answer of Hot to make COM ActiveX object work in IE 64 bit?
Are the types used in your class ole automation compatible? I don't know if jscript checks for oleautomation compatibility up front.

Categories