Silverlight 4, MEF, Export/Import errors, Mefx doesn't want to work - mvvm

Out of frustration and more than 3 days googling up this issue... i have no choice but to bother you guys with my question.
i am creating a Silverlight application. I am using MEF. When i try to run my application i get the following error.
The invocation of the constructor on
type
'IFG.Silverlight.Client.Views.MenuView'
that matches the specified binding
constraints threw an exception. [Line:
25 Position: 47]
and its Inner exception is as follow...
The composition remains unchanged. The
changes were rejected because of the
following error(s): The composition
produced a single composition error.
The root cause is provided below.
Review the CompositionException.Errors
property for more detailed
information.
1) No valid exports were found that
match the constraint
'((exportDefinition.ContractName ==
"MenuViewModel") AndAlso
(exportDefinition.Metadata.ContainsKey("ExportTypeIdentity")
AndAlso
"IFG.Silverlight.Client.ViewModel.MenuViewModel".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))',
invalid exports may have been
rejected.
Resulting in: Cannot set import
'IFG.Silverlight.Client.Views.MenuView.ViewModel
(ContractName="MenuViewModel")' on
part
'IFG.Silverlight.Client.Views.MenuView'.
Element:
IFG.Silverlight.Client.Views.MenuView.ViewModel
(ContractName="MenuViewModel") -->
IFG.Silverlight.Client.Views.MenuView
Ok. my code is very simple since it's a test application.
i have an Interface IRetailModel
namespace IFG.Silverlight.Client.Common
{
public interface IRetailModel
{ ............
then i have a class that implements this interface
namespace IFG.Silverlight.Client.Model
{
[Export(typeof(IRetailModel))]
public class RetailModel : IRetailModel
{ .................
Then I have my ViewModel for the View
namespace IFG.Silverlight.Client.ViewModel
{
[PartCreationPolicy(CreationPolicy.NonShared)]
[Export(ViewModelTypes.MenuViewModel)]
public class MenuViewModel : IFGViewModelBase
{
IRetailModel _model;
[ImportingConstructor]
public MenuViewModel(IRetailModel model)
{
Well, i found that there is a magical tool called MefX that it's supposed to debug deep to the bone your code and tells you what's going on... I havent been able to get this to work.
I followed directions from this article http://blogs.msdn.com/b/nblumhardt/archive/2009/09/24/debug-composition-from-within-visual-studio.aspx
When i try to run it says
Error: Unable to load one or more of
the requested types. Retrieve the
LoaderExceptions property for more
information.
Then went back to Google and i found this Visual MefX (which is the same but with a GUI) and i can load the .xap but basically it gives me the same info that i get from Visual Studio. I can't find the darn [BECAUSE]...
I am really, HONESTLY AND DEEPLY, frustrated with this situation. Can anyone explain to me where am i failing to get MefX to do its job? I know the risk of dealing with these Overnight Frameworks (lack of documentation, buggy, etc etc) that MEF seems to be, but Prism is not a option to me (i feel like buying a M16 to kill a fly when i can use my finger).
Thank you

For future reference, an updated version of Visual Mefx is attached to this blog post: How to Debug and Diagnose MEF Failures. It is also part of MEFContrib, although I'm not sure if the MEFContrib version has all the changes from the version in the blog post.

Related

DotNetFiddle or similar for ClearScript

[I realise this is slighly off-topic for SO but I am asking this as I want to raise a couple of questions around ClearScript and I want to be able to include fiddles to make life easier.]
Is there a usable dot net playground (for example DotNetFiddle) that I can use for some fundamental learning of ClearScript, and what is a minimal bare-bones config. Ideally I would like to be able to get a link to a known-good fiddle that I can fork from. I searched for ClearScript fiddle but the few I found were incomplete or non functional. I am looking for console output only.
I tried this fiddle https://dotnetfiddle.net/rpd5le# but I do not know which Microsoft.Clearscript to reference and keep getting errors such as
Run-time exception (line 8): Inheritance security rules violated while
overriding member:
'Microsoft.ClearScript.HostItem.GetInterface(System.Guid ByRef, IntPtr
ByRef)'. Security accessibility of the overriding method must match
the security accessibility of the method being overridden.
This is the simple code I have to date:
using System;
using Microsoft.ClearScript.V8;
public class Program
{
public static void Main()
{
V8ScriptEngine engine = new V8ScriptEngine();
engine.AddHostType(typeof(Console));
Console.WriteLine("Hello from C#");
engine.Execute(#"
Console.WriteLine('Hello from Javascript');
");
}
}

Warning CS7022 - The entry point of the program is global code; ignoring 'Program.Main(string[])' entry point

so I have an issue where I have this warning in my Error List:
Severity Code Description Project File Line Suppression State
Warning CS7022 The entry point of the program is global code; ignoring 'Program.Main(string[])' entry point. Project DirectoryToProject 23 Active
This is essentially where its throwing
namespace MyProgram
{
class Program
{
static async Task Main(string[] args) => await new Program.MainAsync();
}
static async Task MainAsync()
{.. do stuff.. }
}
That is the line of code that is causing the error. I've tried playing around with the Main class, I did have it with the return type void and had my GetAwaiter and GetResult method called on the MainAsync method.
I've tried researching the error but I've had no luck, so hopefully, this thread will help a few others...
I am currently running on C# 9.0
Visual Studio 2019 Build Version: 16.8.30717.126
EDIT: Forgot to show that the MainAsync was in the file... (Sorry) Im trying to limit the amount of methods I show as 95% of them aren't useful the to question... But the issue is that although my application compiles, when executing my program it quits instantly as if it doesn't know where to start...
EDIT 2:
Thanks to Hans Passant -
If anyone experiences something like this try what he mentioned:
"This is a rather awful C# v9 feature. Project > Properties > Build tab, Advanced button > Language version = 7.3 You should now get a decent error message from the code you didn't know you had to post".
Essentially upon changing back to C# 8.0 I saw it was a different file hidden away causing the issue.
Starting with net5.0, I've found that this error can be caused by having stray semicolons above the namespace keyword. Whether this is a bug or intended behavior is beyond me, however make sure you don't have any standalone semicolons as such:
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
; // This will cause CS7022
namespace Tomoe.Commands.Public
Be sure to check all your files and not just Program.cs
EDIT: Apparently this is intended behavior, see https://github.com/dotnet/roslyn/issues/53472.
TL;DR, semicolons above namespaces are interpreted as top level statements. Because nothing is being called in said statement, the program exits. This is the same as doing
static void Main() {
;
}
in your Program.cs. While I do feel some change should be made, the design decision behind this is quite logical and entirely understandable.
EDIT 2: According to jcouv on Github, this is now becoming an error instead of a warning. Hopefully, this "bug" shall harass us no more!
This can happen if a file (any file) in the project has global code, that's to say statements outside of a class.
As mentioned by others, this is caused by a new C# 9 feature that is called "Top-level statements". This Feature enables you to write statements in the global context and the compiler will create it's own Main() based on that.
In my case I had a semicolon after my using statements in any of my files. As far as I know Visual Studio or the compiler don't give you any option to find this "entry-point" without changing any settings as descripted by others in this thread.
My solution was to just create another "Top-level statement entry point" in my project. Due to the fact that there is only one allowed the compiler complains about that.
I just added a semicolon directly after the using statements in my Program.cs. Because this file is one of the first that are processed by the compiler any other file that contains a "Top-level statement" will cause an error.
I've also seen this compiler error in the following scenario. You've written your code with top-level statements. Later, you decide to absorb that logic into a Main() method. (Maybe you find you now need to return an async Task, or you need to modify it to meet a company coding standard, for example.) Even though the following code block will compile (in VS2022 at least), it generates the error in question with a green squiggly beneath Main:
static void Main()
{
Console.WriteLine("Inside the Main() method");
//Do some other work here
}
Where's the issue? The method declaration is correct, and it will run, but even when this is the only code in the Program.cs file, and even when no other entry point is specified in the project/solution settings, we do not get the expected output:
Even the Microsoft documentation isn't much help in this case, because it pretty much repeats in more detail what the error is saying.
What's missing is the Program class definition. Without it, the compiler is still looking for a top-level statement - which it finds, namely static void. Then the next thing it finds is the Main() method declaration, but it finds this after the (unintended) top-level statement static void. Hence, the error sorta makes sense now.
The fix is to wrap the above code in a Program class:
class Program
{
static void Main()
{
Console.WriteLine("Inside the Main() method");
}
}
And now we get the expected output:

Use of Extbase Repositories in Symfony Command

Im upgrading an extension to work with TYPO3 v10. Since command controllers can not be used anymore, im migrating them to symfony commands as pointed by the documentation. Everything works smooth as heck except for the usage of extbase repository classes. No matter what i query, i never get a result. Since i can't find any useful information on the web and the documentation i hope this may be just something minor.
After debugging for a while i found out that the pid is not determined correctly while building the query settings. I find that kind of strange since my root template has these lines:
plugin.tx_myext.persistence.storagePid = 15403
module.tx_myext.persistence.storagePid = 15403
The repository instances are correctly injected by injectMyRepository() methods. I've tried using the extbase ObjectManager to fetch the class instances instead but the "error" stays the same.
Am i doing something wrong or is it not possible to use extbase repository classes in symfony commands?
After more research i found out that there is some bootstraping missing which results in extension settings (the storageID in my case) not being loaded. From what i've been reading, that behaviour seems intended to prevent extbase booting, i guess?
There is a reference to something similiar in the official documentation: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/CommandControllers/Index.html#initialize-backend-user
Knowing that, i tried to find a method to initialize the missing settings which i could not find. So this does indeed seem like a missing feature.
I developed a workaround which i'm not too proud of, but it's better than nothing (or rebuilding everything to doctrine for that matter). If you stumble upon the same issue, here you go. Just insert and call this method before you fire your query:
public static function initializeConfigurationManager(): void
{
/** #var ConfigurationManager $configurationManager */
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
$tmpConfiguration = $configurationManager->getConfiguration(
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
'myExtensionName'
);
$configurationManager->setConfiguration($tmpConfiguration);
}
That approach exploits the singleton state of the ConfigurationManager. You simply inject the static template of your extension manually and every extbase compound (like repositories) will then use these settings from there on. Lovely.
Be aware however, this is prone to break with future internal changes.

Converting UML class diagram to C++ code(VS 2012)

I am using VS2012 for a course project that we started from scratch, We are to use C++ to create something like this (I think the aggregation part is reversed):
https://www.dropbox.com/s/w2zh7yltbups6cm/class.png
Well , we had that on paper , wrote the code for each class with no problems, except we can't test because each class depends on another that was not finished at the time.
Long story short : each class has its own untested code and VS does not detect any errors whatsoever and based on our previous experience we know that the code is correct, no syntax errors anyway.
When I start compiling some 500 errors come out of nowhere , some of them it says in "time.h" , I thought it was something wrong with the compiler , tried switching to C::B and see if it work but i needed a different compiler and I don't have the time to download any large files ,seriously , deadline in 2 days and internet speed sucks.
doing some research here (and googling around) I narrowed it down to cyclic dependencies and I learned that I can draw the diagram in VS and get code files , unfortunately it does it in C# while I have a C++ code (it has to be C++) .
How can I realize this diagram in C++ ? Which class should include which headers ?
How can I avoid this in the future ?
EDIT:
Solved it by removing all dependencies and disabling pre-compiled headers (Don't really know if I had to) , then I included each .h in its corresponding .cpp , then I included in each .h every header it needs to use.
All that did not really solve my problem , it was the declarations !!!
I did #ifndef myclass , #define myclass to each header and declared the used classes , I think it's what's called "Forward Declaration" (correct me if I'm wrong)
Anyway it finally compiled and I will start testing .
If you have any remarks then by all means , you can add them.
Cyclic "dependency" can be. Why not? Because they are not dependencies, but associations with visible navigability. But you have some problems here.
Reservation should better have navigation to Member. Backward it could be, too. But Reservation should have Member instance as attribute. It is more simple way.
Also Rental is a class representation of association between DVD and Customer. And should have their instances as attributes. Again, back navigation IS possible, but do you need it? Maybe.
Another problem:
Title-DVD aggregation has correct direction, but it should be Composite, for there are no DVD without Title.
Testing: You can do unit tests, isolating classes from other ones by mocking first. After debugging that start to replace mocks with real classes. After that try unit tests without mocking, then normal auto tests, with automatic input/output/comparing.
As for code engineering, download VP UML enterprise "for testing version" and/or Enterprise Architect of Sparx, eval professional version. They both can do code engineering in C++.

WCF Data Service with EF fails to expose imported functions

(I am also using .NET 4.0 and VS 2010.)
I created a function import returning a complex type, as explained at http://msdn.microsoft.com/en-us/library/bb896231.aspx. The function import and new complex type appear in my .edmx file and in the Designer.cs file. However, the function does not appear when I view the service in the browser, and when I add or update a service reference in the client project, the function does not appear there either - as is to be expected, given the first result.
Creating an imported function and using it seems conceptually very simple and straightforward, and one would think it would just work, as Microsoft's step-by-step instructions appear to suggest: http://msdn.microsoft.com/en-us/library/cc716672.aspx#Y798 (which article shows the SP returning entity types - I tried this also, and it doesn't work for me either).
This blog post shows the addition of a method to the DataService class, which Microsoft's instructions omit: http://www.codegain.com/articles/wcf/miscellaneous/how-to-use-stored-procedure-in-wcf-data-service.aspx I tried adding one method returning a list of entity types and another returning a list of complex types, and still had no success. I still could not access the functions, either directly via the browser or from the client application via a service reference.
Thanks in advance for any help with this.
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
MS would do well to add a note to the walkthroughs stating that the above bit of code must be there. (It may be better to enable each operation explicitly than to use "*".)
http://www.codegain.com/articles/wcf/miscellaneous/how-to-use-stored-procedure-in-wcf-data-service.aspx shows that line of code. Also, something it is there in the code, commented out, when one creates the WCF Data Service. Some of us like to delete commented-out code that we aren't using and that seems irrelevant - perhaps doing so a bit prematurely, sometimes.