Microsoft.Bcl.AsyncInterfaces error (in CSVHelper method) when running the application installed by Visual Studio Setup project - wpf

I have a WPF application that reads a CSV file using CSVHelper which I installed using NuGet. Here's the project, system, etc version info.
Microsoft Windows 7 Professional Version 6.1.7601 Service Pack 1 Build
7601
Microsoft Visual Studio Community 2019 Version 16.4.5
NuGet Package Manager 5.4.0
WPF Project Target Framework: .NET Framework 4.7.2
CSVHelper Version: 15.0.5
CSV reader method is straightforward; read a file and put it in a list. Nothing fancy. I'll link the entire project at the bottom so you can download and try it out if you want.
When I run the executable made in either Release or Debug builds, they work fine. They read the file, put contents in a list, and display on a DataGrid just fine. As a next step, I created a standard Visual Studio Setup project, and created an msi installer, which I used to install the app in my PC.
When I run that executable (which is in my Program Files directory), however, the application throws an exception. Here's the exception message and Stack Trace.
Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)
at ReadCSVTest.MainWindow.ReadPeopleList(String path, List`1& people, String& msg)
at ReadCSVTest.MainWindow..ctor()
Since the error says couldn't load the assembly Microsoft.Bcl.AsyncInterfaces, I added that from NuGet and ran everything again, and I still get the error. What's the problem here? What does it mean that Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context.? And why do I only get this exception when I run the executable installed by the Setup project?
Please download the entire project from HERE.

Just so anyone runs into the same issue in the future; as Jones suggested in the comments, downgrading each of the two libraries to following versions fixed the issue for me.
CsvHelper ==> 12.3.2
And
Microsoft.Bcl.AsyncInterfaces ==> 1.0.0

Related

MSB4062 error publishing .NET7 app with publish profile

This is pretty easy to replicate but also code here:
https://github.com/dominicshaw/dotnet-publish-error
create an empty wpf project using .NET7
create a publish profile for ClickOnce
publish via command line (not visual studio)
Publish profile is almost totally standard (view here)
Command line from project directory:
dotnet publish PublishError.csproj -p:PublishProfile=ClickOnceProfile
Subsequent error:
MSBuild version 17.4.0+18d5aef85 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\7.0.100\Microsoft.Common.CurrentVersion.targets(4149,5): error MSB4062: The "Microsoft.Build.Tasks.RequiresFr
amework35SP1Assembly" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKey
Token=b03f5f7f11d50a3a. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, a
nd that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Users\shawd\source\repos\PublishError\Publi
shError\PublishError.csproj]
I have the latest SDKs installed and VS2022 up to date. This only happens via command line - I am able to publish from Visual Studio (I am setting up devops, so require command line).
This happens regardless of adding nuget package for Microsoft.Build.Tasks.Core. Note however nuget package v15.1.0.0 is not available - I have tried 15.1.548 and the latest instead.
Totally at a loss! Any ideas very welcome.
Thanks vm
During the tests with your project and files, I finally managed to publish it successfully with the command dotnet publish PublishError.csproj -p:PublishProfile=FolderProfile.
Here is the document for dotnet publish, as is referred,
The preceding example uses the FolderProfile.pubxml file that is found
in the <project_folder>/Properties/PublishProfiles folder. If you
specify a path and file extension when setting the PublishProfile
property, they are ignored. MSBuild by default looks in the
Properties/PublishProfiles folder and assumes the pubxml file
extension.
And I also succeeded with dotnet publish with your project.
==============================
update on 11/19
So I suppose that the issue is resulted from your definition for -p:PublishProfile=ClickOnceProfile,it will change the path where this command would search for the publish file
A partial answer as my workaround for anyone struggling with a similar problem:
I have found it impossible to do this with the dotnet cli but I can do it with MSBuild if I specifically target 17.4 (VS2022). By default, my Azure DevOps Server 2020 capability is the 2019 MSBuild (15.X), so I have to be explicit:
"C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Current\Bin\MSBuild.exe" /restore /Verbosity:m /t:Publish /p:RuntimeIdentifier=win-x64 /p:configuration=Release /p:PublishProfile=ClickOnceProfile
This works - so in my pipeline I have created a batch file which runs this, then I copy the files to my ClickOnce location.
Not ideal, but a working pipeline.
Interesting side note - this dotnet cli command which should be idenitical (and indeed uses the correct 17.4 MSBuild) - does not work (with the same error):
dotnet msbuild -target:Publish -property:RuntimeIdentifiers=win-x64;Configuration=Release;PublishProfile=ClickOnceProfile

The invocation of the constructor on the Cefsharp.Wpf.ChromiumWebBrowser that matches the specified binding constraints threw an exception

Line number '81' and line position '18' ---> System.IO.FileNotFoundException: Could Not load file or assembly 'Cefsharp.Wpf.ChromiumWebBroser.NoInliningConstructor()'.
It works on my machine, but when I release an EXE/MSI file and install to a machine of my client mechanic it throws the exception above.
The CefSharp library requires the Visual C++ Redistributables. Install them to your clients machine or add them as a prerequiste to you installer. Choose the appropriate redistributable for your version:
CefSharp 65.0.0+ requires VC++ >= 2015
CefSharp 51.0.0 to 63.0.0 requires VC++ 2013
CefSharp 45.0.0 to 49.0.0 (.NET Framework 4.0) requires VC++ 2013
CefSharp 43.0.0 and below (.NET Framework 4.0) requires VC++ 2012
If this does not help, check if all the files that are required are copied to your clients machine. Check this list for the required files for CefSharp. Compare the expected files from your build output folder to the installed files, because the exception clearly states that either CefSharp.Core.dll or one of its dependencies is missing.
There is a known issue that installers sometimes do not include unmanaged resources. If any resource or DLL is missing, then you have to manually add them to your setup.

Can Fody and its plugins be used with .NET Core (3.0)?

As the title says, I'm having trouble getting Fody, and the plugin Fody.PropertyChanged, to work in .NET Core 3.0, or any .NET Core version. Reading the issues on the respective GitHub pages doesn't answer my question, nor am I able to find any relevant answers.
Once installed I cannot run my WPF project anymore and I am given the following error:
The target process exited without raising a CoreCLR started event.
Ensure that the target process is configured to use .NET Core.
This may be expected if the target process did not run on .NET Core.
The program '[21820] CalculationToolsApp.exe' has exited with code -2147450749 (0x80008083).
Any suggestions?
EDIT: I found out that I (maybe) cant use "Fody.Costura" with "Fody.PropertyChanged" like this in the FodyWeavers.xml file:
<Weavers>
<PropertyChanged />
<Costura />
</Weavers>
Which shouldn't be a problem because with .NET Core I can create a single file application anyway. Removing the Costura reference from the FodyWeavers.xml solved my problem!
It should work. Fody is compatible with .NET Standard.
Create a new WPF app using the WPF App (.NET Core) template in Visual Studio 2019 or using the dotnet new wpf command
Install the Fody and PropertyChanged.Fody NuGet packages
Add a file named "FodyWeavers.xml" with the following contents to the project:
<Weavers>
<PropertyChanged />
</Weavers>
Build
If you then decompile the assembly using a decompiler such as for example dotPeek, you should see the injected code as expected, e.g.:
public string GivenNames
{
// Method get_GivenNames with token 06000009
get
{
return this.<GivenNames>k__BackingField;
}
// Method set_GivenNames with token 0600000A
set
{
if (string.Equals(this.<GivenNames>k__BackingField, value, StringComparison.Ordinal))
return;
this.<GivenNames>k__BackingField = value;
this.<>OnPropertyChanged(<>PropertyChangedEventArgs.FullName);
this.<>OnPropertyChanged(<>PropertyChangedEventArgs.GivenNames);
}
}
Costura didnt work in wpf with .net core 3.1 for me either.
In .net core 3.1 you can use this instead:
Build -> publish -> create profile -> Edit "Configuration"
Target Runtime = win-x64 (or what ever target system you want, but NOT "portable")
expand "File Publish Options"
check: Produce single file
save
When you now choose build -> publish -> publish button it will create the single file.
It seems to be that they stopped the costura project because of the "Single-file executables" feature of .net core. Though this feature is still behind costura because you have to set a target runtime.
https://github.com/Fody/Costura/issues/442
In dotnet core 3 there are two new features
Single-file executables
Assembly linking
With these features included in the dotnet tool set, the value
proposition of Costura is greatly diminished. With that in mind I
think long term Costura should cease to be used as people transition
over.
Please comment with any input.
Plan:
disable issues
PR will still be accepted but only for bug fixes
add note to readme
add note to nuget description
write a warning in
update for .NET 5:
for .NET 5 and the current visual studio version 16.10.2 the wizard changed. I could not get this to work with the wizard anymore though i checked the options for single file etc.. But using the console worked: tools -> command line -> developer command prompt -> enter this:
dotnet publish -r win-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true
.NET 5 not compiling to single file executables

How to configure PDFNet for .NET application to publish to Citrix server? (AnyCPU)

So I have been trying to config the project to make it work on our server via Citrix.
I used this line of code to set the path:
private static pdftron.PDFNetLoader loader = pdftron.PDFNetLoader.Instance().Path(String.Format(#"{0}\{1}",
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(IndexUIZoom)).Location), #"PDFNet"));
I got this error every time (bin is where the .exe file is):
INFO Program [(null)] - Path: [bin]\PDFNet -
ERROR Program [(null)] - System.IO.FileNotFoundException: Could not load file or assembly 'PDFNet.dll' or one of its dependencies.
The specified module could not be found. File name: 'PDFNet.dll'
Everything works fine on local machine. I got the error above whenever I run from Citrix, or log into the server machine and run from there.
Most likely your server is missing the MS VC++ Runtime dependencies. Developer machines usually have them installed as part of a Visual Studio installation, but servers often do not. You can download MS VC++ installers from MSDN.
To find the exact one you need to download please see section 3.2.1 of the Getting Started Guide for PDFNet .Net below. Note you need to also match the runtime 32 or 64 bitness of your process, for both PDFNet.dll and the MS VC++ runtime.
PDFNet .Net 4.0+ Getting Started Guide
PDFNet .Net 2.0-3.5 Getting Started Guide
https://www.pdftron.com/documentation/windows/guides

VS2017 15.4 Preview "Windows Application Packaging Project" tool failed to generate a working app

I added the new "Windows Application Packaging Project" that comes with vs2017 15.4 preview.
When adding my project to the "Applications" and debugging the packaging project I have the following error:
System.IO.FileNotFoundException: 'Could not load file or assembly
'System.Runtime, Version=4.1.2.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified.'
InnerException: FileNotFoundException: Could not load file or assembly
'System.Runtime, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified.
My project is running perfectly if I debug it directly or run it directly using the EXE.
If I extract the files from the .appxbundle and try to start the EXE, it doesn't work either. (XXXXXX.appxbundle\XXXXXX.appx\*.*)
I noticed that in the extracted .appxbundle folder, all System.XXX DLLs are not there. They should be (94 dlls are missing).
Is there a problem with the packaging tool ?
UPDATE:
Link to dev portal: https://developercommunity.visualstudio.com/content/problem/122252/windows-application-packaging-project-tool-failed.html
This is very likely a bug in the way the packaging project is collecting files. Looks like we're already tracking this bug in the Developer Community. Also, we're tracking another related issue for ClickOnce.

Resources