I have two installers in separate assemblies, one in the assembly that the bootstrap code is, and one in another references assembly.
I'm bootstrapping like such:
container = new WindsorContainer()
.Install(FromAssembly.InThisApplication(), FromAssembly.Named("My.Other.Assembly"));
The installer in the second assembly ("My.Other.Assembly") for some reason is being called twice, which is obviously causing problems in trying to register duplicate components.
Any ideas why that might happen?
FromAssembly.InThisApplication() will scan the current assembly and all assemblies that have the current assembly name as a prefix (including the dot though).
So, if your app is called either My or My.Other, then My.Other.Assembly will be scanned both as a result of FromAssembly.InThisApplication() and as a result of including it explicitly.
Could it be that this is what's messing with you?
Related
I'm quite new to MVVMCross but I've been actively using it for two weeks, at work and in a school project, and I am really enjoying it! Unfortunately, I've been stuck on the school project for 2 days now : we're asked to do a mobile Jabber client. This is not a big deal since I started it using Matrix XMPP library, which does most of the job and is easy to use. I decided to restart my project using MVVMCross, in order to have cleaner separated code and add a Windows Phone project, but Matrix absolutely needs System.Xml.Linq, and I can't get the core PCL to compile :
The type 'System.Xml.Linq.XElement' is defined in an assembly that is not referenced.
You must add a reference to assembly 'System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
As shown in Stuart Lodge's tutorial videos, I'm using profile 104, the the faulting dll is really present in the folder, I can't add it manually to project's references since VS prevents me from doing it (gently explaining that it's automatically loaded since .Net portable subset is included in references), I've updated and repaired my VS install "just in case"... and have no more idea left.
So, here are the questions :
is it really possible to use System.Xml.Linq with MVVMCross? or did I miss the big title explaining that what I'm trying to do is stupid?
if yes (that'd be great!) did/does someone experience the same problem? Even more interesting : did someone find a solution?
Thanks in advance!
Additional info : Windows8(x64), VS2012 Ultimate, trial license (school project...) for Xamarin.Android
UPDATE : following Stuart's answer, I compiled and ran the BestSellers sample, which uses System.Xml.Linq... without any problem. As it comes with an explicit reference to System.Xml.Linq (see first link in answer), I tried :
to delete it (and a few others) : VS holds it's promises, and really includes needed references as long as .Net Portable Subset is referenced, so everything rolls smooth.
to manually add this reference via Notepad to my .csproj : it doesn't change anything.
One thing tickles me in Stuart's answer : "perhaps it is something to do with the way the matrix uses XML.linq". Since the Matrix type I'm trying to use is just a descendant of System.Xml.Linq.XElement, which is widely used in BookViewModel.cs from sample, what could possibly be wrong with that?
"Solution" : The problem seems to be due to Matrix requiring a special version of System.Xml.Linq, which is not the one included when profile 104 for building PCL. I used file linking method as a workaround to share the core, and that works, though this is less elegant, readable, and harder to maintain...
Yes it is possible to use at least some of System.Xml.Linq
For example, see the BestSellers sample
csproj file - https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20BestSellers/BestSellers/BestSellers/BestSellers.csproj#L49
example XML linq use - https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20BestSellers/BestSellers/BestSellers/ViewModels/BookViewModel.cs#L44
For the problem you are seeing, I'm really not sure what the error is - perhaps it is something to do with the way the matrix uses XML.linq? You might have more luck of you open up this question to other tags like portable-class-library, XML-linq and windows-phone.
I have defined list_t in my project that got list module API like list_pop(). But now I have to use MySQL lib to communicate with DB, but the MySQL lib still got its list implements, and also defined a list_pop() API. In my other modules, I have to link both of them, and comes the conflict.
One of my solution is, separately include header file for different list API calling, this works well, but while some function need to call both of MySQL::list_pop() and local::list_pop(), how to notify the compiler the correct link point? Is there some GCC trick that can do these without any changes to local::list_pop()?
For most practical purposes, you are going to have to rename one or the other set of functions. It is probably easier to rename your own than those of MySQL.
The simplest approach is to simply add a prefix that has a higher probability of being unique (enough), such as your initials, or the codename of your project, or something. Or you can rename everything to avoid collisions, being aware that MySQL might add a new function in the future.
This is exactly why namespaces were invented for C++, and why C projects usually have systematic prefixes on sets of functions.
There is a way to solve this. Refactor your list_pop() to, say, my_list_pop().
There is one other way to solve this,
Looking at the header of the MySQL my_list.h here, https://github.com/lgsonic/mysql-trigger/blob/master/mysql/my_list.h you can see that list_pop is just a macro, and its binded at compile time, not at runtime(hence not a real library function). Changing list_pop of MySQL to list_pop_my(just in the #define) can make it do what you want it to do.
The reason I ask this is if the log4net.dll is not in the GAC and not in the current Executing Assembly directory, castle Logging facility will not find it.
I have built a class library that is going to be used by multiple client applications to do logging using Castle and Windsor, I have noticed that I don't need a reference to the log4net.dll in my class library at all, it just needs to be able to see the dll at runtime.
So I am just wondering where the reference should truly be because if I put in my class library it is not copied over to clients even though copy local is true, I think because it actually is never used directly.
You definitely need to provide log4net.dll to get Castle logging facility to work (assuming you have configured the logging facility to use log4net). You are correct that you no longer need to reference log4net directly in your projects, because you will now be using Castle.Core's ILogger interface to actually write log messages. Your application still depends on log4net, albeit indirectly.
Visual studio normally handles these kinds of "indirect" references (A depends on B depends on C) properly (it copies C over to A's output directory). However, it does not copy the indirect reference (it does not copy C to A's output directory) when C is in the GAC on the machine performing the build.
My guess is that you have log4net.dll GAC'd on your development machine.
To resolve this, you either need to remove log4net.dll from your GAC (and from the GAC on any machine where you'll be building the app), or you must explicitly reference log4net.dll in your top-level executable (project A in the example above) and set "copy local" to true. This forces the compiler to copy the dll to the output directory.
This issue was also discussed in this SO question
container.Register(
AllTypes.Pick().FromAssembly(typeof (UserRepository).Assembly)
.WithService.FirstInterface());
Currently the code above will work fine if the interface are also in the same assembly but it will blow up if IUserRepository is from a different assembly.
Is auto registration from two different assemblies possible? Am I missing something here?
Yes, it's possible to define auto-registration where the interface is defined in a different assembly. We do it, although we use a slightly different syntax:
container.Register(AllTypes
.FromAssemblyContaining<ConfigurationService>()
.Where(t => t.Name.EndsWith("Service", StringComparison.Ordinal))
.WithService
.FirstInterface()
.Configure(reg => reg.LifeStyle.PerWebRequest));
I can't say if the different API usage makes a difference, but I would assume that it doesn't. Rather, I would guess that the cause of the error you experience is that perhaps the assembly containing the interface isn't available.
Check if Fusion can load the type from that application at all.
I spent this morning in trying to figure out where the system.linq.expressions namespace is. The following is what I did:
In VS 2008, Create a new C#/Smart Device/Windows Mobile 6 Professional SDK/.NET CF v3.5/Class Library
Used SqlMetal (in Program Files/Microsoft SDKs/Windows/v6.0A/Bin) to generate the data context.
Added the data context .cs file into the project.
Compile and many errors for missing namespaces: System.Data.Linq, System.Data.Linq.Mapping, System.Linq.Expressions
After some research added System.Data.Linq.dll in c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5 (The dll was not directly listed when I choose to add reference and I used "browse" tab to finally located the one, which is for normal framework)
Compile again, less errors, but still System.Linq.Expressions namespace is missing.
The document says System.Linq.Expressions is in System.Core.dll but it seems my System.Core.dll (located in Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE) contains much less namespace than document says.
Thanks in advance!
The Compact Framework does not support LINQ to SQL. All objects in the documentation for System.Data.Linq confirms this by being completely devoid of the "supported in the CF" icon. For example, look over at the docs for DataTable, which is supported. You'll see a little icon by each supported method/property.
You cannot "add" support by simply referencing a desktop assembly like you did in your step 5. The CF cannot consume full framework assemblies, for a variety of reasons.
Dynamic code generation (Reflection.Emit) is not available in NETCF. What this means is that a lot of features that depend on this is not available, this includes DLR (dyanmic language runtime and hence languages like IronRuby), Linq-to-SQL/
If you just want the Linq.Expressions and you are doing your own stuff with it i.e. not trying to get linq to sql working then you can use the System.Linq.Expression stuff from the db4o guys.
I am using it on my project using linq to objects.
db4o linq implementation