2

I'm running into a weird issue. I have exactly the same code. On one machine, it works flawlessly. On the other, It throws a InvalidOperationException on GetExport<IXSocketServerContainer>

The offending line is:

  _serverContainer = Composable.GetExport<IXSocketServerContainer>();

Here's a screenshot of the exception as well: screenshot.

Any ideas?

The only difference I can think about are that one machine is Win 8, and the other is Win 7.


Further details: took the solution that worked (win 8), copied as is to other machine (win 7), clean all packages, reinstall all nuget dependencies, went over all project adding or reimporting the dependencies, still now working (on the win 7 machine), though the project will build without errors.

Took that non working (yet compiling) project back to the first machine, and it won't work on that machine either. Utterly out of ideas.

Noctis
  • 11,507
  • 3
  • 43
  • 82

2 Answers2

3

Ok, Seems this was off the bat ...

It has nothing to do directly with XSockets.

What happens is a (known?) difficulty (read: bug) in VS.

Project A (.exe) includes project B (.dll). Project B has dependencies that will be copied to it's output directory. Project A will not get the dependencies that project B needs, and will burn and crash at runtime.


Solution:
Create a Post build event for the project (project properties -> Build Events) that looks like

copy /y source target

You probably want to have double quotes around your source and target, to avoid failing if they contain spaces.
You want the /y to overwrite files in the target.
You might need to play a bit in order to get the right syntax as well:

copy /y "$(ProjectDir)..\project_b\$(OutDir)some_mask.dll" "$(ProjectDir)$(OutDir)"

Related links:

Visual Studio Post Build Event - Copy to Relative Directory Location

Copy file(s) from one project to another using post build event...VS2010

Copy bin files on to Physical file location on Post Build event in VS2010

VS BUG: https://connect.microsoft.com/VisualStudio/feedback/details/694561/copy-local-private-true-private-on-a-project-reference-needs-to-also-copy-what-the-target-project-marks-as-copy-local


Addendum:

It seems that in addition to the above, if you run XSockets from a folder that has # (sharp, or hash character) in it's path ... the server is going to throw the above exception as well.

Community
  • 1
  • 1
Noctis
  • 11,507
  • 3
  • 43
  • 82
  • Hi, I would like to know more about this error. Tried to reproduce it but it works fine on my machine. Whats your setup? – Uffe Jun 22 '14 at 16:43
  • 1
    Hi Uffe, I've opened a thread on the XSockets developers as well about the "#" issue. Otherwise, it happened on Win 8 x64 machines, and Win 7 x64. – Noctis Jun 23 '14 at 02:38
  • Glad it helped someone else. I remember i was highly frustrated by that issue :) – Noctis May 01 '15 at 02:03
0

The reason for this is that we use the following method to locate the assemblies.

public static string GetAssemblyDirectory()
{
    return HostingEnvironment.IsHosted
                        ? HttpRuntime.BinDirectory
                        : Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
}

So, since we use:

new Uri(...)

the "#" will be removed and the path will not find the assemblies, and then you will get the "Sequence contains no matching elements..." exception.

However, it should work if you add the path manually before using the plugin framework... Something like.

Composable.AddLocation(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

You can ofcourse add any location, this "sample" would load all assemblies/exe in the bin folder of the executing assembly/exe In 4.0 we will use the way described above and skip the "new Uri(..)" stuff.

Let me know if you have any issues.

Uffe
  • 2,275
  • 1
  • 13
  • 9