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

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.

Related

.Net Application SideBySide loading fails COMException (0x80040154)

My .Net 4.5.2 WPF Application is deployed to C:\Program Files\Folder A\FolderB. Its copied to that location by a custom deployment service that is basically a copy job with some additional features. The application itself is xcopy deployable, given you have the required C++ runtimes, .Net Framework installed.
The application includes several com components, registered via the application manifest file, which used to work just fine. After an update to the applications binary files, several calls in the form System.Activator.CreateInstance fail
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
If i simply rename the application folder to c:\Program Files\FolderA\FolderC everything is working correctly
Attaching ProcessMonitor and WinDbg, i can trace that the application is searching the registry for the given classid, doesnt find it and then, if started from the first folder fails as described above. Started from the renamed or copied folder the process loads the associated dll and just goes on.
Any hints on diagnosing this issue?
To anyone struggeling as I did: as far as i currently see it, the problem was the SideBySide Cache.
In short, Windows caches the manifest information for an application, and if it determines the application has not changed, uses the cache (you will notice that the existing external manifest is never loaded by your process).
In my case the executable did not change, but the rest of the application, including the manifest information.
The solution is to touch the modification date of the executable, causing the cache to become invalidated.
Basically also answered in this question

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.

Referencing Projects from Windows Service

I am in the middle of trying to write my first windows service using C# and .NET framework and am having trouble referencing a project within the same solution within the service. My MVC solution structure within VS2012:
1 MVC project (web app project)
1 additional processing project (used for extended processing within controllers)
1 service project
1 install shield le project (successfully installs the service project)
Within my service (which I want to fire every x mins) I am referencing methods in the extended processing project that intellisense is able to detect when I am writing code within the service project (I have a using extendedProcessingProject; using webAppProject; and a project references to the extendedProcessingProject and web app project).
The service installs to my local pc without errors. When I start the service I have an error being logged that I cannot seem to figure out:
Exception body: ReminderEmailService Object reference not set to an instance of an object. System.Collections.ListDictionaryInternal
System.NullReferenceException: Object reference not set to an instance of an object.
at ReminderEmailService.ReminderEmailService.ReminderEmails(Object source, ElapsedEventArgs e)
at ReminderEmailService.ReminderEmailService.SendReminderEmails(Object source, ElapsedEventArgs e)
Void SendReminderEmails(System.Object, System.Timers.ElapsedEventArgs)
I know can see though using the System.Diagnostics.Debugger.Launch();
List<SessionReminder> sessions = Queries.GetSessionsToRemind();
//sessions does not have a value, method returns a list of 1
//I suspect this is a project reference issue
debugString += "sessions: \n" + sessions.ToString();
//exception thrown on this line--I suspect because sessions is null
I am using the .NET4.0 (not client profile) on all projects within my solution. Any insight on how to enable my windows service to correctly access these assemblies (webappproject.dll and extendedProcessing.dll) would be much appreciated, as these dll's are being installed by install shield.
It might not be an actual assembly reference issue. The error you are seeing is that the runtime is complaining about accessing methods/fields/properties of a null object. This indicates that your code is accessing an uninitialized object.
The exception you've displayed doesn't look like an issue with referencing assemblies. It looks like a plain ordinary bug in the code, not a missing assembly.
I always create a test harness for a windows service to enable me to run the service as a simple Windows Forms application to make debugging easy.
Separate your service implementation into a separate assembly from the assembly with the actual windows service. Create another project WPF/Winforms with a simple start/stop button. From both the windows service and winforms application reference the assembly containing the functionality that runs within your service.

WcfSvcHost throws LoaderException when attaching to IIS7 process, but everything seems to work?

I have been implementing RSA security for a project I am working on.
I'm using the SecurID4Net files found on the web to get this rolling, which by default are targeted to the .Net 2.0 framework, ANY CPU.
I created a derived SqlMembershipProvider which references the SecurID4Net.Interfaces project, targeting .Net 4.0, any CPU.
My class lib "Services" references the SqlMembershipProvider, also targeting Any CPU.
My web app "Services.Web" references the "Services" lib, .Net 4.0, Any CPU.
I'm not using the client profile for any assembly targeting .Net 4. Every reference I have described here has Copy Local set to True.
I have my local IIS default web site set up to my output folder for the web project, so I can Ctrl-Shift-B and browse my IIS folder. When my client app signs in for the first time (possibly 2 or 3 times), it works fine, but after that sign ins fail. Additionally, when attaching to the IIS7 process (Services.Web), I would get the following error:
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)
The DLL it is having problems loading is the SqlMembershipProvider I created.
So, I changed the SecurID4Net.Interfaces project to target .Net 4.0, and recompiled. It seems to work consistently now (still testing this part), but CTRL-ALT-P to attach to the IIS process still results in the WcfSvcHost error popping up before I can actually attach to the process... everything else seems to be working.
I'm running my VS as admin so I can attach to an IIS process;
All references described are set to Copy Local = true;
All assemblies are targeting .Net 4.0 Full Profile;
All assemblies are reachable, not blocked by the copy operation to the server where this is hosted;
To my knowledge no syntax issues with the web.config.
Anyone have any ideas why this error keeps popping up? Why would this error pop up when everything seems to be working?
I think I found the answer almost immediately. After inspecting each AssemblyInfo.cs file in the chain of projects, I found this in my SqlMembershipProvider assembly:
[assembly: AssemblyCulture("EN-us")]
I removed the value so it's an empty string.
I had a very similar issue in another project I worked on a few months ago where the web site had this filled in, and the web site worked on the very first load, but every load thereafter failed with a very cryptic error which, after drilling down, found that it could not load the assembly, giving a FileNotFoundException.
I don't know why this tiny, simple attribute would cause so many headaches...
EDIT: I'm 99% certain this was it. When I attach to my IIS process I no longer get a WcfSvcHost error.

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

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).

Categories

Resources