How can I load a WPF User Control Library dynamically from a console application?
Problem description:
I have an assembly that is compiled as WPF User Control Library and want to load it from a console application using reflection. Unfortunately, I receive a System.Reflection.ReflectionTypeLoadException with this message:
Unable to load one or more of the requested types. Could not load file or assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Loading "normal" Class Library assemblies works without problems. Even if they have dependencies, everything is loaded correctly. However, loading fails as soon as the assembly contains WPF.
What I tried:
I tried different ways to load the assembly, but all of them fail with above exception:
Using System.ComponentModel.Composition with imports and exports.
Using Assembly.LoadFrom().
Using a custom AssemblyLoadContext as described at learn.microsoft.com.
I made sure that the path to the assembly is correct. If I specify invalid paths, the error message is different.
Details:
The assembly has target framework .NET Core 3.1 and output type Class Library. It uses the Microsoft.NETCore.App and the Microsoft.WindowsDesktop.App.WPF frameworks.
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
The console application has target framework .NET Core 3.1 and output type Console Application. It uses the Microsoft.NETCore.App framework.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
</Project>
Related
I have converted a WPF project to the new csproj SDK format. It shows some properties such as:
Company: $(Authors)
Where do I define the variable $(Authors) and similar such variables? I am building my project both locally and in Azure DevOps.
This is MSBuild specific, it does not depend on SDK project style in particular, see:
Define and reference properties in a project file
Define a tag with the name of the property inside a PropertyGroup.
<Project Sdk="Microsoft.NET.Sdk">
<!-- ... -->
<PropertyGroup>
<Authors>John Doe, Jane Doe</Authors>
</PropertyGroup>
<!-- ... -->
</Project>
Since you refer to a property named Authors, you probably mean a special property that is used for NuGet packaging, see pack target inputs and Package properties.
I'm trying to get started with module development using Abp framework, the potential of using the framework is huge with the community and the abp.commercial support if it's needed, but it's not always easy to up and running the application. Let me explain...
I have created a new module: abp new sample.module -t module. ABP CLI version 3.3.1
After that, I have added a new entity in Domain (member.cs) and using AbpHelper.GUI to auto-generate all the code.
🎉My module works correctly using Hosts/*.web.unified test project. Well done! :).🎉
NOTE: see here if you want to know how to solve a tricky issue for me at this point.
Next, I have added assemblies one by one to the Host App. I have mapped:
Module.Application --> Host.Application
Module.Application.Contracts --> Host.Application.Contracts
Module.Domain --> Host.Domain
Module.Domain.Shared --> Host.Domain.Shared
Module.EntityFrameworkCore --> Host.EntityFrameworkCore
Module.HttpApi --> Host.HttpApi
Module.HttpApi.Client --> Host.HttpApi.Client
Module.Web --> Host.Web
Finally, I added Module Dependencies and Configurations, following this post.
🎉 Restore, build, dotnet ef migrations, and *.HostApp.DbMigrator work like a charm and the database is updated based on the entities in the module. Cool! 🎉
But... when I run my Host App and click on the new module menu contributor the route doesn't work 😒 but it seems to be correct based on the page structure of the module and it worked fine using Hosts/*.web.unified test project inside the module.
I tried several times with no lucky 🤦♂️
Something is missing in the code that I cannot see.
Any help is really appreciated.
Because the Host application and Module are in different solutions. I was missing to include an assembly (Module.Web.Views.dll) into the Host web project.
Good day.
I have created a .NetCore2 webapp and would like some guidance on how you get
windows.forms working on it. (VS2017)
This is the error I get basically:
Dot Net Core and Azure Storage: Could not load file or assembly System, Version=4.0.0.0
Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
The project builds but the moment I call the api it fails to detect the dll. (In code it detects the dll fine)
I have added the dll to the project, also followed the instructions of adding it to your project.json. (in my case: package.json)
"frameworks": {
"netcoreapp1.0": {
"imports": [
"net46",
"net40"
]
}
},
Also added the required references to my csproj folder.
<PropertyGroup>
<TargetFrameworks>net452;netstandard1.3</TargetFrameworks>
</PropertyGroup>
How to use System.Windows.Forms in .NET Core class library
"frameworks": {
"netstandard1.6": {
"dependencies": {
"NETStandard.Library": "1.6.0"
}
},
"net40": {
"frameworkAssemblies": {
"System.Windows.Forms": {}
}
}
}
I am still getting the same error.
I know it is not advised to use .Net framework in a .NetCore app.
Am I going to have to port the framework app so it works in a Core enviroment?
The reason i want to just use .NetFramework is that the app already works fine, I just have to get the screens shown to the user.
I also read somewhere that Windows.Forms is not supported with .NetCore in some versions of the framework.
If so, any links to help with this?
I am quite a noob with .NETCore so some of my questions might not make sense or are ignorant.
Thanks
I am using WPF prism for modular application development and each module that is present in the module catalog file is in different folder and they get added and removed from the region one at a time.Each module gets loaded from a its own folder and application exe is at different location. All the dependencies of the module is in its own folder.
In one module (dll) the view which gets added to region is having resource dictionary and with Source of the ResourceDictionary as :
Source="/UIControls.Wpf.MessageBox;component/Themes/Generic.xaml"
If the resource DLL (UIControls.Wpf.MessageBox.dll) is present at the place where application exe is present then it works, that means view get added to the region. But this resource DLL has to be present at folder where module DLL is present(All the dependencies of the module is in its own folder). So if i remove this DLL from where application exe is then it gives FileNotFound exception and the module does not get loaded.
How can I give source/path of the resource dictionary as codebase of the module? Source I don't want as application exe relative,I want the source as the path from where module is getting loaded i.e its codebase. Is there any way or other syntax so that source code is not the application exe relative. Please give me some solutions. One option I have got is to use AssemblyResolved event. But i dont want to use that.
When I'm deploying application to WP7, application throws exception:
System.Windows.Markup.XamlParseException: The invocation of the constructor on type 'Microsoft.Maps.MapControl.Map' that matches the specified binding constraints threw an exception. [Line: 24 Position: 16] ---> System.MissingMethodException: File or assembly name 'System.Windows.Browser, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7CEC85D7BEA7798E', or one of its dependencies, was not found.
When I'm deploying same application to emulator or mobile device(in debug mode) everything works as expected.
Do you have any idea how to make it work without debug mode?
First, check if System.Windows.Browser is referenced in your project, and if it already was, check in its property tab that it's marked as "Copy". The issue seems to be that your app is unable to find it at runtime.
If a System.Windows.Browser file is referenced, check if it's the one the control requires (2.0.5.0)