MEF Parts not found for deployed app, but found in Debug mode - wpf

I checked a lot of MEF questions here but I can't imagine what my problem is. Here's what's happening:
I have a desktop WPF app that I'm deploying with AdvancedInstaller. I use .NET 4.0 and MEF to compose parts. Some parts are in the main project, so they are inside the app.exe file. Other parts are inside class libraries that reference the main project, so they are inside somename.dll files.
The problem:
While running the app from VS, both in Debug and in Release, everything is fine. Once I deploy the app, some of the dlls say that they have no parts (zero) to export.
I checked the following:
all dlls are available in the deployment and the catalog is finding the files
the export types and names are correct, after all, everything is working while in Visual Studio
when I try to add the parts from the dlls, I get that the number of parts is zero ONLY IN DEPLOYMENT.
This is the code that's not findind parts in the deployed app:
var catalog = new AggregateCatalog();
string path = Environment.CurrentDirectory.ToString();
DirectoryCatalog qualitycontrol = new DirectoryCatalog(".", "QualityControl.exe"); //this is my main assembly
DirectoryCatalog qualitymix;
catalog.Catalogs.Add(qualitycontrol); //this finds the parts and always works fine
if (File.Exists(path + #"\QualityMix.dll"))
{
qualitymix = new DirectoryCatalog(".", "QualityMix.dll"); //the file exists in the deployment
catalog.Catalogs.Add(qualitymix); //the "qualitymix" catalog shows more than 20 parts if run with VS, but 0 parts in deployment
}
The only thing that works (but it's very slow to start the app) is the following:
var catalog = new DirectoryCatalog(".", "*");
This has the problem that it needs to check more than 100 files present in the working directory, and I cannot deploy my plugin dlls in a different dir.
Why is it that a DirectoryCatalog looking at all files finds the parts, but a DirectoryCatalog looking at a single part does not? How can I debug this issue if it only happens in the deployed app?
---Edit: this problem is only happening with certain dlls, the files are found and for other dlls the parts are also found. I'm using the same Export/Import procedure in all dlls, but somehow some of them show no parts in deployment
Anything you can suggest will be helpfull, thank you guys!
NEW INFO!
I tried loading my dll with an AssemblyCatalog. It works in Visual Studio (Debug and Release) but when deployed I get the following errors:
1st try:
if (File.Exists(path + #"\QualityMix.dll"))
{
qualitymix = new AssemblyCatalog(Assembly.LoadFile(path + #"\QualityMix.dll")); //file is loaded and parts found in VS
catalog.Catalogs.Add(qualitymix);
}
Error: The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018).
Second try:
if (File.Exists(path + #"\QualityMix.dll"))
{
var name = AssemblyName.GetAssemblyName(path + #"\QualityMix.dll");
qualitymix = new AssemblyCatalog(Assembly.Load(name));
catalog.Catalogs.Add(qualitymix);
}
Error: Could not load file or assembly 'QualityMix.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
I've looked for questions about these errors but nothing has been helpful so far. All projects are built for All CPUs, and the references look ok (this dll uses the same references as other projects that are loading ok).
Edit 2:
I tried the suggestion by #SuryaBhaskar to use LoadFrom instead of Load
if (File.Exists(path + #"\QualityMix.dll"))
{
qualitymix = new AssemblyCatalog(Assembly.LoadFrom(path + #"\QualityMix.dll"));
catalog.Catalogs.Add(qualitymix);
}
But I get the same error: Could not load file or assembly 'QualityMix.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I managed to solve this issue by moving the code of the problematic dll to a new project. This solved the issue, somehow... though the reason remains a mistery to me.

Use LoadFrom instead of LoadFile or Load.If you use Load it will have conflicts with other assemblies on current AppDomain

Related

React suddenly responding with index.html instead of javascript imports

Recently I've been unable to load javascript scripts to my webworkers in react for some reason. It always responds with index.html.
My config is simply a standard create-react-app app. The screenshots are from my actual project but I have confirmed that the problem persists if I create a new project and try to initialize a minimal example.
Each ffmpeg.* file is affected. This is also not specific to ffmpeg since another library had the same issue - thankfully the initialization of that library is simpler so I was able to simply put that libraries worker-file in the public folder - and that worked.
It might be a stupid question but I'm really at my wits end here and I can't figure out how to investigate further.
Thank you <3
EDIT:
It works if I put all the files it is trying to hit in the public folder - so it has to be some kind of context issue(??) This seems like a really stupid way to go about it. It's not in a worker at the point of loading - it's the worker loader that fails to access the stuff it needs in the node_modules folder, (core script, worker script and wasm code). Whet?

The component 'LiveCharts.Wpf.DefaultLegend' does not have a resource identified by the URL '/LiveCharts.Wpf;component/defaultlegend.xaml'

I have been programming on a winforms project for about a month days. Recently one of the form designers always show an error page.
When the project is just loaded on VS, there's no error. After I do some modification then rebuild it will show the error page of:
The component 'LiveCharts.Wpf.DefaultLegend' does not have a resource identified by the URL '/LiveCharts.Wpf;component/defaultlegend.xaml'.
and the call stack shows:
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at LiveCharts.Wpf.DefaultLegend.InitializeComponent() in c:\Users\btord\Documents\Projects\LiveCharts\WpfView\DefaultLegend.xaml:line 1
at LiveCharts.Wpf.Charts.Base.Chart..ctor() in c:\Users\btord\Documents\Projects\LiveCharts\WpfView\Charts\Base\Chart.cs:line 82
at LiveCharts.Wpf.CartesianChart..ctor() in c:\Users\btord\Documents\Projects\LiveCharts\WpfView\CartesianChart.cs:line 40
at LiveCharts.WinForms.CartesianChart..ctor() in c:\Users\btord\Documents\Projects\LiveCharts\WinFormsView\CartesianChart.cs:line 46
at Controls.Chart.MyChart.InitializeComponent()
at Controls.Chart.MyChart..ctor()
I checked the path but found no 'c:\Users\btord' directory and a few days ago I moved my Documents directory to D driver.
Sometimes after I build on release it will show another error page of:
Could not load file or assembly 'LiveCharts.WinForms, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0bc1f845d1ebb8df' or one of its dependencies.
And there's no error in source code of the designer at all, neither when building. The execute file can run healthily.
It seems to commonly happen when multiple copies of live charts dll's are present in a solution build.
For me it was used both in the main executable and a plugin class library building in a sub folder. The effect is two copies of the Live Charts dll's in different folders which it doesn't like.
Packages.config
If using a packages.config file to handle references you can set the LiveCharts references to "CopyLocal"=false for the extra projects. This stops multiple copies of the dll's being included the build. It will happily use the copy loaded in the main project.
Package References
Sadly there isn't an option to not copy the files when using the newer style package references.
Removing extra copies post build seems the easiest workaround I've found.
In Project Properties, Build events page, post build event command line box add
del $(TargetDir)LiveCharts.*
$(TargetDir) is your projects output path.

How can I fix compilation for relative paths using StackExchange.Precompilation?

For https://github.com/StackExchange/StackExchange.Precompilation:
We have some shared views in separate library where we have installed StackExchange.Precompilation. We have to load those views along with the normal web project's views. We have the latest version of StackExchange.Precompilation installed from NuGet in both projects. I am doing the assembly loading like this:
// Register precompiled view engine
ViewEngines.Engines.Clear();
List<Assembly> viewAssemblies = new List<Assembly> { typeof(HomeController).Assembly };
viewAssemblies.AddRange(AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.ToLower().Contains(".web")));
Log.Debug().Message("Looking for views in: {0}", string.Join(", ", viewAssemblies.Select(a => a.FullName))).Write();
ViewEngines.Engines.Add(new PrecompiledViewEngine(viewAssemblies.ToArray()));
In the web project, we return views the normal way: return View("Index");
When using PrecompiledViewEngine we get an error when trying to render relative names like that:
The view 'Index' or its master was not found or no view engine supports the searched locations.
The following locations were searched:
~/util/Views/Example/Index.cshtml
~/util/Views/Shared/Index.cshtml
util is the alias of the application in IIS. We don't have any areas registered.
When I copied the PrecompiledViewEngine class from GitHub - it worked! Am I missing something that will make the version distributed through NuGet work?
Copying the code over turned out not to work. I must have been trying something else at the time that made it work for that specific case.
The problem is actually a bug in StackExchange.Precompilation. I've created an issue there: https://github.com/StackExchange/StackExchange.Precompilation/issues/12

WPF - My application installer is crashing

Its a .NET 3.5, x86 application that I built. It works. But when I try to install it using a custom installer, it fails with this error The App has stopped working. In the dialog box, it shows path to two files. In one of the files, I found this.
<ProblemSignatures>
<EventType>CLR20r3</EventType>
<Parameter0>app.installer.exe</Parameter0>
<Parameter1>1.0.0.0</Parameter1>
<Parameter2>5321e224</Parameter2>
<Parameter3>App.Installer</Parameter3>
<Parameter4>1.0.0.0</Parameter4>
<Parameter5>5321e224</Parameter5>
<Parameter6>4</Parameter6>
<Parameter7>e</Parameter7>
<Parameter8>System.IO.FileNotFoundException</Parameter8>
</ProblemSignatures>
Is there a way I can find what file was not found for Parameter8 above?
In the other file, I found this Exception Code: 0xe0434f4d but that didn't help much either.
Update:
I'm installing by adding a separate project that is pointing to the .application file of the actual app like below.
try
{
Uri deploymentUri = new Uri(deployManifestUriStr);
iphm = new InPlaceHostingManager(deploymentUri, false);
}
It was missing a dll. I tried copying that dll to the folder where exe was being run from and it works. But I couldn't still figure out how to find the NAME of the missing file. I just found out it was missing a dll by trial and error.
Unless I get a better answer, this is the answer, I guess. Make sure you have all dlls the exe is expecting in the exe directory.

AppManifest.xml not getting updated by SL build

I'm starting an SL project in VS2010, and I'm finding that the AppManifest.xml file isn't being updated by the build. This causes the xap to fail to load in the browser, throwing an InitializationException. Doesn't VS maintain this file for you?
I noted that the Build Action listed for the AppManifest.xml file is currently "None", but I'm not sure what I should change that to, if anything.
The problem turned out to be that I didn't have any Application class in my project, nor the required App.xaml. (I had somehow deleted these files when attempting to customize the solution.) This caused the xap to fail to load, and the error message led me to believe that the root cause was the AppManifest.xml, which generates the AppManifest.xaml file.
This was a mistake. Fixing the Application class and the App.xaml solved the problem.

Resources