SOAP/WCF client accessing a service that uses AWSSDK.dll (Amazon S3) - c#

I'm encountering something I did not expect. I have a C# client that accesses a SOAP/WCF service, and the SOAP/WCF service is (trying to) use the AWSSDK.dll to get/put/enumerate objects stored in Amazon S3. Odd thing is, for some reason, the client is getting a FaultException`1 was unhandled with the error text:
Could not load file or assembly 'AWSSDK, Version=1.3.19.0, Culture=neutral, PublicKeyToken=cd2d24cd2bace800' or one of its dependencies. The system cannot find the file specified.
Any idea why in the world the client would need to have the DLL loaded? The server hosting the service has it loaded.
In any case, I added the DLL to the client (I have no clue why I would need to, but just for sanity's sake), and lo and behold, even with the DLL added as a reference, I get the exact same error.

Fault exceptions are generated from the service side so that indicates to me that your service is having the problem with the AWSSDK.dll reference. Make sure that your service has the reference to the file and that when you rebuild the dll is in the bin folder of the service startup project.
To build navigate to menu Build -> Batch Build.. -> Select All -> Rebuild.
You should not have to copy the file manually as the build process should copy it to the proper location if you have it referenced.
Another thing would be to check that you are building under the correct configuration. If the dll is x64 and you are running x86 that might also produce the above error (not exactly sure though).

Related

Permissions to load assembly at runtime in ASP.NET MVC

I'm currently working on a function for my website that should work like this:
User upload an dll
I load the dll inside another app domain (with Assembly.LoadFrom) to inspect it with reflection
Unload the app domain and delete the .dll file
This works perfectly fine when I do it locally but when I upload it to my server I get:
Failed to generate files: Could not load file or assembly '/the/path' or one
of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
So the "Operation is not supported" make me a bit curious. Is it some kind of permission that I need to set the server? Or is it something I can fix through my config? Or is it simply that my server actually don't support it at all?
The only information I can see on my Windows/IIS server is that it use .NET version 4.
Set project Property Local copy = true ,if you are loading using reflection then provide deployment Item at Class level it will work.

Exception occurring while connecting a C# client application to XSockets Server

I am using XSockets for having two way (web socket based) communication between an XSockets Server and an existing C# desktop client application.
I have integrated code in my existing client application for communicating with XSockets Server.
For now, XSocket Server starts as a separate console application. It starts fine with no problems.
Then I am using following pseudo code block in my C# client application:
XSocketClient client = new XSocketClient("ws://127.0.0.1:4509/MyController", "*", false); //Error occurs right on execution of this line
client.Open();
Following is the Exception snapshot that throws out;
Exception of type 'XSockets.Plugin.Framework.Exceptions.ExportException' was thrown
Custom Message: Failed to load exported interfaces in assembly Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Source: XSockets.Plugin.Framework
Stack Trace: at XSockets.Plugin.Framework.Composable.SatifyImportsExports()
at XSockets.Plugin.Framework.Composable.Initialize()
at XSockets.Plugin.Framework.Composable.GetExport[T]()
Type: System.IO.FileNotFoundException
Note: If I create a new C# windows form client project and try executing this code, it executes fine and connection is successfully made to the XSocket Server.
Means there is something disturbing from inside my existing client project.
What could the possible reason for this weird exception ? Any ideas? Thanks
Edit: I have noted that if I manually remove Microsoft.Practices.EnterpriseLibrary.Validation DLL from my Bin folder, it raises same kind of exception but with a different custom message this time. I mean then the error is related to some other DLL (of my existing application) present in Bin folder.
I ran into a similar problem yesterday and solved it like so:
Composable.ClearPluginFilters();
Composable.AddPluginFilter("XSockets.*.dll");
This code was called just before I bootstrapped my application and started my server. I know the question is kinda old but if anyone else end up here aswell.
Source from Google Groups
Ok found answer to my own raised question.
There can be two things related to this issue:
Microsoft.Practices.EnterpriseLibrary.Validation.dll was causing problem from the Bin => Release/Debug folders. From Visual studio project references list, right clicked the Microsoft.Practices.EnterpriseLibrary.Validation reference, clicked on Properties and set [Copy Local] property to false. XSocketsClient was now connecting successfully to the XSockets Server but some other logic of my existing application was still needing Enterprise Library which being Copy Local ==> false, was not coming available to the .Net Runtime, so it showed an Exception whenever Runtime was coming across those parts of code.
To resolve the later issue encountered because of removal of Enterprise Library reference, I added again Microsoft.Practices.EnterpriseLibrary.Validation reference and also added one another DLL Microsoft.Practices.EnterpriseLibrary.Common.dll and added its reference to my client application.
Now my client application connects fine to XSocket Server and also now no issue comes with the inclusion of Enterprise Library reference.
Seems like there are some things essential needed by Enterprise Library at runtime which lie in that second DLL.

C# Cannot Connect To WCF Service When Called From COM Interop

I have a C# class library that works fine when called from a C# application. However, it also supports COM Interop so that older C++ clients can also call it. The C# Class library has a WCF service reference in it. The WCF call works fine from a C# call but when called from COM Interop, I get an error stating:
"Could not find default endpoint element that references contract 'xxxx' in the ServiceModel client configuration section....."
The reference is in the app.config or more specifically the .config which gets built when you build the DLL. It seems that when called from a C# application, the DLL knows where to look for this config file (i.e. the same directory as the dll) and hence finds the needed info. However, when called from COM Interop, it seems it must be looking somewhere else for it and not finding it.
Does anyone know how I fix this and make it work in both scenarios?
Using a .config file in a COM server is quite unpractical. The one that System.Configuration looks for is not associated with the DLL but with the EXE. Is name is foo.exe.config where "foo" is the name of the EXE and must be stored in the same directory as the .exe. A COM server can't predict what EXE is going to load it.
But you can make it work by hand by storing the .config file with the right name in the right directory.
In .NET it is always the executable that has a configuration file, not the .dlls it uses. Even if it is the .dll that needs configuration information, it has to be included in the config file of the application.
By default, the CLR will look for a config file called .config in the same directory as the exe. If this happens to be an old C++ program makes no difference, at least according to my experience. You can just copy the config file to the directory of the C++ program, rename it to match the executable and you're good to go.
If you want a solution that just works everywhere, consider expressing the configuration in code, possibly after manually loading the needed configuration information from some source.

WCF Service in Sharepoint 2010 can't find my Custom ServiceHostFactory class

I made a great WCF service in my dev environment, then when I pushed it up to production I got various errors saying "This collection already contains an address with scheme http..."
So, I created a Custom ServiceHostFactory class for my service.
Now when I upload it I get:
The CLR Type 'WCFServices.MultipleHostFactory' could not be loaded during
service compilation. Verify that this type is either defined in a source
file located in the application's \App_Code directory, contained in a
compiled assembly located in the application's \bin directory, or present in
an assembly installed in the Global Assembly Cache. Note that the type name
is case-sensitive and that the directories such as \App_Code and \bin must
be located in the application's root directory and cannot be nested in
subdirectories.
I checked the GAC and my assembly is indeed there.
Can anyone explain why this error is occuring?
Again, I am using .NET 3.5 on Sharepoint 2010
Is it "WCFServices.MultipleHostFactory" or "WCFServices.MultipleHostsFactory"? If its the first, thats why because that namespace does not match that you said in your question.
It turns out that I was able to remove one of the bindings from the application host configuration file. After talking with the administrator, I found that he had two bindings for port 80. One was IP:80:[DNS name] and the other was :80:
We agreed to get rid of the :80: binding and the WCF service was able to deploy to SP.
If anyone ever runs into that CLR loading issue, please post with a solution. I still don't have a good explanation for that problem.

Adding a WCF Service to a project

I have a C# WinForms Project which contains some WCF service definition files which I have created in the project by adding standard classes (not using Add Item > WCF Service).
The project contains some dependencies that require me to build the project for x86 processors.
If I edit the app.config file with the WCF Service Configuration Editor and try to use the "Create New Service ..." wizard, and then browse to the project EXE file (in the debug folder) I get an error, (which I've read is because I'm targeting the x86 processor):
Could not load file or assembly 'EXE_FILE_NAME' or one of its dependencies. An attempt was made to load a program with an incorrect format.
So, upon changing the target to All CPUs, compiling the project again, and then trying to create the service in the WCF Service Configuration Editor again, I now get a different error:
Could not load file or assembly 'SOLUTION_NAME, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
(To clarify, I CAN still compile the project when targeting all CPUs, but get an error at runtime due to a dependency)
Is anybody able to help me with this problem, so I can add the services defined in app.config file using the wizards in WCF Service Configuration Editor? (I think that if I add the services to the WCF Service Configuration Editor when targeting All CPUs I can make any modifications thereafter, regardless of the target)
When debugging, look at the exception detail. From what you've described my guess is you will an assembly loading error in the fusion log because the dependencies of the WCF service can't be satisfied by looking in the default locations.
Say for example you're referencing MrCritter.MyService.dll which defines a WCF service and has a dependency on something like log4net or nHibernate. As long as nothing from those dependencies is leaking into the WCF host (eg returning an ILog) yes you'll be able to compile fine but will get ReflectionTypeLoadException thrown when trying to instantiate the service class if those dependencies aren't somewhere it can find (eg in the executing directory, in GAC etc).

Categories

Resources