System.Runtime.CompilerServices.Unsafe produce unexpected behavior in Xamarin Forms - c#

I built a complete Xamarin From application. When I change build mode to Release I get this error message:
Severity Code Description Project File Line Suppression State
Error The "LinkAssemblies" task failed unexpectedly.
Mono.Linker.MarkException: Error processing method: 'System.Void
Microsoft.Extensions.Primitives.InplaceStringBuilder::Append(System.String,System.Int32,System.Int32)'
in assembly: 'Microsoft.Extensions.Primitives.dll' --->
Mono.Cecil.ResolutionException: Failed to resolve System.Void
System.Runtime.CompilerServices.Unsafe::CopyBlockUnaligned(System.Void*,System.Void*,System.UInt32)
at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference
reference) at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference
reference) at
Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body) at
Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.ProcessQueue() --- End of inner
exception stack trace --- at
Mono.Linker.Steps.MarkStep.ProcessQueue() at
Mono.Linker.Steps.MarkStep.ProcessEntireQueue() at
Mono.Linker.Steps.MarkStep.Process() at
Mono.Linker.Steps.MarkStep.Process(LinkContext context) at
Mono.Linker.Pipeline.Process(LinkContext context) at
MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext&
context) at
Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver
res) at Xamarin.Android.Tasks.LinkAssemblies.Execute() at
Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at
Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() EClinicForDoctor.Android
After searching on the Internet, I find this solution which says:
The resolution to this issue is to make sure you have the latest supported Android SDK versions, and set the Target Framework to Use latest installed platform. It's also recommended that you set the Target Android Version to Use Target Framework Version and the minimum Android version to API 15 or higher. This is considered the supported configuration.
Thus I update Android SDKs, set Target Framework and set minimum Android version to API 15.
However, I still get the same error. Another solution says that I should update NuGet Packages. I found that the version of the package System.Runtime.CompilerServices.Unsafe is 4.3.0 and there is an update for this package. When updating the package, the error no longer appear but another problem occur. When the app deployed, it run and stop without any error message. The mobile just exit from application without showing any error message. This happens when the package System.Runtime.CompilerServices.Unsafe is on version higher than 4.3.0. I tried to remove the package and the same problem happens again. How can I solve this problem?

I've seen this issue popup at a few different locations now. There is some discussion going around it like here: https://github.com/xamarin/xamarin-android/issues/1196
This Github issue also lists some (possible) solutions, the one with the most positive feedback seems to be this one:
Here's a functioning workaround. It's hacky and ugly but works with
minimum fuss. Put this in an XML file and <Import> it in your Android
csproj file at the end. It works at least for System.Buffers
<!-- Workaround for https://github.com/xamarin/xamarin-android/issues/1162 -->
<Project>
<Target Name="ReplaceRefAssemblies" AfterTargets="_ResolveAssemblies">
<ItemGroup>
<ResolvedAssembliesFixedWindows Include="#(ResolvedAssemblies->Replace('\ref\','\lib\'))" />
<ResolvedAssembliesFixedUnix Include="#(ResolvedAssemblies->Replace('/ref/','/lib/'))" />
<ResolvedAssembliesFixed Include="#(ResolvedAssembliesFixedWindows)" Condition="#(ResolvedAssembliesFixedWindows) != #(ResolvedAssemblies)" />
<ResolvedAssembliesFixed Include="#(ResolvedAssembliesFixedUnix)" Condition="#(ResolvedAssembliesFixedUnix) != #(ResolvedAssemblies)" />
<ResolvedAssemblies Remove="#(ResolvedAssemblies)" />
<ResolvedAssemblies Include="#(ResolvedAssembliesFixed)" />
</ItemGroup>
</Target>
</Project>
Another uses the XML from above and says:
I've just copied the content from the link above and saved as UnsafeFix.xml file in the Android project folder.
Then just added: <Import Project="UnsafeFix.xml" /> at the end of android .csproj file, just before
Cleared everything, recompiled and it finally worked!

Finally I get the solution. One of the comments in the issue provided by #Gerald Versluis solve the problem:
I follow these steps of hongliyu2002
https://forums.realm.io/t/could-not-load-assembly-system-runtime-compilerservices-unsafe-during-startup-registration/974/4
Go to C:\Users%user%.nuget\system.runtime.compilerservices.unsafe\4.4.0, and
delete "ref" folder then make a copy of "lib" folder and rename the
copy back to "ref".
Cleanup all the "bin" and "obj" folders in the projects.
Rebuild and run..
This simple workaround , works for me :) My current version is
Xamarin.Forms 2.5.1.444934

Related

An item with the same key has already been added MAUI C#

When I try to run my program in release mode, it give this error:
Severity Code Description Project File Line Suppression State
Error XAGJS7004 System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Xamarin.Android.Tasks.TypeMapGenerator.GenerateRelease(Boolean skipJniAddNativeMethodRegistrationAttributeScan, List`1 javaTypes, String outputDirectory, ApplicationConfigTaskState appConfState)
at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types, TypeDefinitionCache cache)
at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res)
at Xamarin.Android.Tasks.GenerateJavaStubs.RunTask()
at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 MauiApp1 C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.440\tools\Xamarin.Android.Common.targets 1438
It is strange because in debug mode it works fine and I can't find any answer online.
Window snippet
There is fore sure some incompatibility between MAUI and .NET7, but you can set your project to use previous NET6 version following few steps:
Discover installed SDKs and keep note of the exact version 6
dotnet --info
SDKs list
Move to project folder and create a global.json file, it sets the NET SDK to be used. Be sure to set the installed SDK version:
dotnet new globaljson --sdk-version 6.0.301 --roll-forward disable
Restore workloads required by your project:
dotnet workload restore
Open project in Visual Studio, confirm to reload the project if requred.
Now your project will be built using NET6 SDK.
I solved it by uninstalling .net7, I found on Maui's github page people with the same problem and I think it will be fixed in the future.
It remains a shame Maui is not yet ready for .net7
Had the same problem, working on debug, this exception on release.
I solved it by: Clean Maui solution -> delete bin and obj -> Close Visual Studio -> Rebuild -> Working
Hope this helps if you didn't try

dotnet publish of a Blazor WASM project errors with An item with the same key has already been added

Really struggling with an issue publishing a Blazor WASM project that is using .NET 6.
Previously, it was on .NET 5, and there were no issues with building / publishing the app.
I've updated it to .NET 6, by essentially updating the nuget references for:
Microsoft.AspNetCore.Components.WebAssembly (to 6.0.0-rc.2.21480.10)
Microsoft.AspNetCore.Components.WebAssembly.DevServer (to 6.0.0-rc.2.21480.10)
We've updated to .NET 6 due to a requirement on DynamicComponent
Running locally during development is fine.
During our build pipeline, I am executing the following to publish the app:
dotnet publish .\Web\Web.Connect --configuration debug --output output
The output that I am getting is:
Web.Connect -> C:\git\core\Web\Web.Connect\bin\debug\net6.0\Web.Connect.dll
Web.Connect (Blazor output) -> C:\git\core\Web\Web.Connect\bin\debug\net6.0\wwwroot
Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(404,5): error : System.ArgumentException: An item with the same key has already been added. Key: C:\git\core\Web\Web.Connect\obj\debug\net6.0\build-gz\bxkpRzBw.gz [C:\git\core\Web\Web.Connect\Web.Connect.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(404,5): error : at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) [C:\git\core\Web\Web.Connect\Web.Connect.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(404,5): error : at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) [C:\git\core\Web\Web.Connect\Web.Connect.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(404,5): error : at Microsoft.NET.Sdk.BlazorWebAssembly.ComputeBlazorPublishAssets.GroupExistingStaticWebAssets(Dictionary`2 assemblyAssets, Dictionary`2 nativeAssets, Dictionary`2 satelliteAssemblyAssets, Dictionary`2 symbolAssets, Dictionary`2 compressedRepresentations) [C:\git\core\Web\Web.Connect\Web.Connect.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(404,5): error : at Microsoft.NET.Sdk.BlazorWebAssembly.ComputeBlazorPublishAssets.Execute() [C:\git\core\Web\Web.Connect\Web.Connect.csproj]
Ok - so some asset is trying to be published multiple times in ComputeBlazorPublishAssets?
Found information indicating that adding <ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles> to the *.csproj might help here, but it has made no difference.
I have ensured that the wasm-tools have been installed via dotnet workload install wasm-tools.
Running a "Publish" via VS 2022 also gives the same error.
I am at a loss as to how I can debug this, or figure out what is getting generated twice, or how to fix this issue.
Thanks.
Ok,
After a significant amount of investigation looking at the binlog files, I have managed to track this down to the fact that my referenced library (which is a netstandard 2.0 project shared with other projects in the solution) was also outputting an app.config file (possibly due to an earlier time when we targeted both netstandard2.0 and net472).
Looking at the MSBuild bin logs:
So, there were two compressed files with the same name - one was referencing the actual *.dll, but the other was referencing *.dll.config
I deleted the app.config (it wasn't really needed and was probably there due to some historic reason) and it's now publishing as expected.

unable to build xamarin forms 5.0.* locally from sources

Due to some custom reasons, we have some custom built-in features in the XF (like the XAML-based toolbar button and changing private-internal to the public classes, plus virtualizing some methods). As the result, we are dependent on the custom version of the XF NuGet package.
It worked (almost always) perfectly until the version XF5.0. I have a dedicated virtual machine with Windows and preinstalled VS for those purposes.
When I'm trying to build XF from sources using the next command
.\build.ps1 -Target NugetPack -ScriptArgs '--packageVersion="5.0.0.2013"'
I get the error:
Successfully created package 'L:\src_github\xf_patch_release-5.0.0-sr3.1\artifacts\Xamarin.Forms.Maps.WPF.5.0.0.2013.nupkg'.
NuGet Version: 5.9.1.11
Attempting to build package from 'Xamarin.Forms.temp.nuspec'.
Object reference is not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at NuGet.Packaging.PackageBuilder.<>c.<ValidateReferenceAssemblies>b__173_1(NuGet.Frameworks1204671.NuGetFramework groupFramework)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other)
at System.Collections.Generic.HashSet`1..ctor(IEnumerable`1 collection, IEqualityComparer`1 comparer)
at NuGet.Packaging.PackageBuilder.ValidateReferenceAssemblies(IEnumerable`1 files, IEnumerable`1 packageAssemblyReferences)
at NuGet.Packaging.PackageBuilder.Save(Stream stream)
at NuGet.Commands.PackCommandRunner.BuildPackage(PackageBuilder builder, String outputPath, Boolean symbolsPackage)
at NuGet.Commands.PackCommandRunner.BuildFromNuspec(String path)
at NuGet.CommandLine.PackCommand.ExecuteCommand()
at NuGet.CommandLine.Command.ExecuteCommandAsync()
at NuGet.CommandLine.Command.Execute()
at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)
An error occurred when executing task '_NuGetPack'.
Error: One or more errors occurred. (NuGet: Process returned an error (exit code 1).)
NuGet: Process returned an error (exit code 1).
I've tried to use different methods to get rid of this non-understandable issue, but nothing happened. I've tried to use the latest actual release-5.0.0-sr3.1 tag and the latest version of the branch 5.0.0
I've tried to change some settings in the build.cake file, to unload some projects from the solution (like UWP-related ones, which usually caused a lot of errors). I've tried to build the solution on my working computer (and environment) - I got the same result.
Then I switched to building the solution in the VS directly and started getting issues like:
Before calling the main task to build: .\build.ps1 -Target NugetPack... I always call the .\build.ps1 -Target provision to ensure that I haven't missed some required tools on each Windows OS.
Is there something that I have missed?
I've found out that I'm using a different version of the NuGet package manager, which I had to install globally on my OS. The right version can be found in the XF's Pipelines (https://dev.azure.com/xamarin/public/_build, see the Windows-related builds).
After I've changed the global version to 5.6.0, the build script started generating the *.nupkg file for the Xamarin.Forms project itself correctly.
...

I have an error with WebDriver.dll in visual studio Chrome version must be between 70 and 73. CHROME WEB DRIVER

I have updated my chrome without thinking to much about it as I am fairly new with selenium however this has caused the following error in visual studio.
An unhandled exception of type 'System.InvalidOperationException' occurred in WebDriver.dll. Additional information: session not created: Chrome version must be between 70 and 73.
I have tried to update the libraries but all my libraries are up to date.
Here are dose libraries and the version.
Selenium.Support 3.141.0
Selenium.Chrome.WebDriver 74.0.0
Selenium.WebDriver 3.141.0
NunitTestAdapter 2.1.1
What can I do to fix this error without downgrading chrome. Thank you very much.
UPDATE Thanks to Dazed I found In packages.config
<package id="Selenium.WebDriver.ChromeDriver" version="73.0.3683.68" targetFramework="net461" />
And I replaced the version with my version.
<package id="Selenium.WebDriver.ChromeDriver" version="74.0.3729.6" targetFramework="net461" />
Also my csproj has the following lines.
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.73.0.3683.68\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.73.0.3683.68\build\Selenium.WebDriver.ChromeDriver.targets'))" />
</Target>
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.73.0.3683.68\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.73.0.3683.68\build\Selenium.WebDriver.ChromeDriver.targets')" />
When I replace the 73.0.3683.68 with 74.0.3729.6 I get the following error
Severity Code Description Project File Line Category Suppression State
Error This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Selenium.WebDriver.ChromeDriver.74.0.3729.6\build\Selenium.WebDriver.ChromeDriver.targets. AutoFillForm C:\Users\Junior\Desktop\columbia project\erp_columbia\erp_columbia\AutoFillForm\AutoFillForm\AutoFillForm.csproj 106
Despite the fact the the files exists in my packages folder as you can see on this image.
I was facing the same issue.
To solve the issue i did following steps:
Go to manage nuGet packages..
then go to browse tab and search the package with keyword: "Selenium.Chrome.WebDriver"
(For other browser, install corresponding package)
and then install it. (Note: if it is already installed then remove the package before installing it.)
update your chrome driver from here: http://chromedriver.chromium.org/downloads
and save it to your local machine and give the path of it into your code
For reference, you can visit my github page Google Login by selenium
Try to run my code by replacing your email id and password.

Error deploying ClickOnce application - Reference in the manifest does not match the identity of the downloaded assembly

I'm trying to deploy a ClickOnce application, but installation fails on the client. Here's the error log:
PLATFORM VERSION INFO
Windows : 6.1.7601.65536 (Win32NT)
Common Language Runtime : 4.0.30319.1
System.Deployment.dll : 4.0.30319.1 (RTMRel.030319-0100)
clr.dll : 4.0.30319.1 (RTMRel.030319-0100)
dfdll.dll : 4.0.30319.1 (RTMRel.030319-0100)
dfshim.dll : 4.0.31106.0 (Main.031106-0000)
SOURCES
Deployment url : http://MyProduct.com/download/workstation/MyProduct%20Front%20Desk.application
Server : Microsoft-IIS/7.5
X-Powered-By : ASP.NET
Deployment Provider url : http://MyProduct.com/Download/Workstation/MyProduct%20Front%20Desk.application
Server : Microsoft-IIS/7.5
X-Powered-By : ASP.NET
Application url : http://MyProduct.com/Download/Workstation/Application%20Files/MyProduct%20Front%20Desk_1_0_0_7/MyProduct%20Front%20Desk.exe.manifest
Server : Microsoft-IIS/7.5
X-Powered-By : ASP.NET
IDENTITIES
Deployment Identity : MyProduct Front Desk.application, Version=1.0.0.7, Culture=neutral, PublicKeyToken=df343a0868ab2d74, processorArchitecture=msil
Application Identity : MyProduct Front Desk.exe, Version=1.0.0.7, Culture=neutral, PublicKeyToken=df343a0868ab2d74, processorArchitecture=msil, type=win32
APPLICATION SUMMARY
* Installable application.
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of http://MyProduct.com/download/workstation/MyProduct%20Front%20Desk.application resulted in exception. Following failure messages were detected:
+ Reference in the manifest does not match the identity of the downloaded assembly MyProductSiteServer.exe.
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
There were no warnings during this operation.
OPERATION PROGRESS STATUS
* [03/17/11 11:51:04] : Activation of http://MyProduct.com/download/workstation/MyProduct%20Front%20Desk.application has started.
* [03/17/11 11:51:04] : Processing of deployment manifest has successfully completed.
* [03/17/11 11:51:04] : Installation of the application has started.
* [03/17/11 11:51:05] : Processing of application manifest has successfully completed.
* [03/17/11 11:51:06] : Found compatible runtime version 4.0.30319.
* [03/17/11 11:51:06] : Request of trust and detection of platform is complete.
ERROR DETAILS
Following errors were detected during this operation.
* [03/17/11 11:51:30] System.Deployment.Application.InvalidDeploymentException (RefDefValidation)
- Reference in the manifest does not match the identity of the downloaded assembly MyProductSiteServer.exe.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.DownloadManager.ProcessDownloadedFile(Object sender, DownloadEventArgs e)
at System.Deployment.Application.FileDownloader.DownloadModifiedEventHandler.Invoke(Object sender, DownloadEventArgs e)
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
at System.Deployment.Application.DownloadManager.DownloadDependencies(SubscriptionState subState, AssemblyManifest deployManifest, AssemblyManifest appManifest, Uri sourceUriBase, String targetDirectory, String group, IDownloadNotification notification, DownloadOptions options)
at System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available.
The main exe I need to deploy is MyProductFrontDesk.exe, which has a dependency on MyProductSiteServer.exe - and that appears to be where the error is being thrown: "Reference in the manifest does not match the identity of the downloaded assembly MyProductSiteServer.exe."
Which manifest needs to be corrected? And how?
There was an issue with Visual Studio 2008 which is solved by not embedding the default manifest - one of the comments on that article suggests the problem still exists in Visual Studio 2010.
In project properties -> Application tab -> Resources -> checkbox Icon and manifest, the setting "Embed manifest with default settings" caused the problem. Setting it to "Create application without a manifest" fixes the problem.
I had the same issue when I added a reference to another project.
The way to solve this was enabling ClickOnce Security Settings in all referenced projects as Ian explained here (emphasis mine):
For me, the way this was resolved was to ensure that all the Projects under the Solution which exposed the "Security Tab" in their "Project Properties" had the Option "Enable ClickOnce Security Settings" Ticked with the Option "This is a full trust application" Selected. This has to do with creating the Manifest correctly and the application will not install if these options are not set on all the Projects within the Solution that require it.
I believe this is the proper way to fix it when making a reference to another project under the same solution.
The linked forum post has expired by now, but it's available on archive here.
I was encountering the same problem, but my solution was very different.
My ClickOnce application was referencing another EXE file project in my solution, so when the client downloaded it, and there was another EXE file, that one didn't have a manifest.
Removing the dependency on another executable solved my problem.
I confirmed that the issue also exists in Visual Studio 2010. Selecting "Create application without a manifest" in Project Properties - Application - Resources solved the problem.
I have experienced the same error when deploying with the project set to Debug. When it was changed back to Release there was no error.
This can also happen if you have two different versions of a NuGet package referenced in different DLL files in your project. In my case I was using a framework called Catel, and I had a newer version referenced in one DLL file than another (oversight), but this caused ClickOnce to spit out this error. Referencing the same version resolved the problem.
I had the same problem, but my solution was to change the 'Platform target' to 'x86' (Project Properties -> Build Tab). It was set to Any CPU. As soon as I changed the setting and republished, the ClickOnce installer was able to complete.
I had exactly the same issue. I could not remove the dependency as it was needed by the main project. The second project was a console project.
I changed to Class Library, and then it all worked.
I had the same issue, and I tried all of previous suggested solutions here, and all of them didn't work.
I fixed it by changing the update location. From project properties -> Publish -> Updates. Change the update location to your published folder.
Another workaround, in case the dependency exe with the bad app manifest cannot be changed (say coming from a NuGet package). The binary can be included as content with a dummy extension so ClickOnce does not try validating the manifest and then renamed during app startup.
csproj:
<Content Include="..\packages\<package>\lib\<app>.exe">
<Link><app>.exe.bin</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<ItemGroup>
<PublishFile Include="<app>">
<Visible>False</Visible>
<Group>
</Group>
<TargetPath>
</TargetPath>
<PublishState>Exclude</PublishState>
<IncludeHash>True</IncludeHash>
<FileType>Assembly</FileType>
</PublishFile>
</ItemGroup>
App.xaml.cs:
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
var appDir = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
if (!File.Exists($"{appDir}\\<app>.exe"))
{
File.Copy($"{appDir}\\<app>.exe.bin", $"{appDir}\\<app>.exe");
}
}
}
If you have one main program that references another then you have to do the "Create application without a manifest" trick on the main program's Program:
Project --> Properties --> Application Tab -->Resources --> Manifest -->drop down "Create application without a manifest"
and then switch over to the referenced program's Project Properties and repeat the process.
I had the same issue a couple of minutes ago, and below are the steps that I used to solve it.
Key
a = Main project (the project you want to publish, e.g. myProduct)
b = Reference project (e.g. MyProductSiteServer)
Checklist
Navigate to properties -> Application -> Resources -> check icons and manifest (for both a and b)
Navigate to properties -> Build : make sure that a and b are on the same target platform
Navigate to properties -> Security and make sure that a and b have these settings checked: "Enable ClickOnce security settings" and "This is a full trust application"
Navigate to properties -> Publish : I recommend you change the path of the publishing folder
ALSO SOLVED FOR ClickOnce .exe calling .exe calling .exe.
I had this problem also, using VB.NET in Visual Studio 2010.
I have a ClickOnce Windows Forms application that references a second Windows Forms application that in turn references a third Windows Forms application. (These second and third applications are EXE files rather than DLL file for simplicity, as they are equally likely to be run stand-alone or called with properties passed to them.)
I had to comment out BOTH the second and third applications' manifest contents per:
Walkthrough: Manually Deploying a ClickOnce Application
It works perfectly.
I use mage.exe to generate my manifest. Adding this to my .csproj fixed the issue. You may also try the -nowin32manifest compiler flag; I've not tested it. I don't see stuartd's "Create application without a manifest" in Visual Studio 2017; I think this is what it does though.
<PropertyGroup>
<NoWin32Manifest>true</NoWin32Manifest>
</PropertyGroup>
I also have this in my .csproj:
<GenerateManifests>false</GenerateManifests>
I had this exact same issue with my VS 2019 application.
I have tried creating the application without a manifest however that did not work.
What did work however was the following:
Go to Build-->Publish-->Application
Click on the "Assembly Information" button
Tick the "Make assembly COM-Visible" option
Hopefully, this helps!
it seems like the issue is caused by the setup.exe in vs 2019. it seems that the exe won't update its version when doing a new deployment. the workaround for me is to
delete everything in the deployment folder.
uncheck "Create setup program to install prerequisite components" in Properties => Publish => Prerequisite.
do a deployment.
come back and re-enable "Create setup program to install prerequisite components".
guess this process will force vs 2019 to update setup.exe to the correct version.
also Project --> Properties --> Application Tab -->Resources --> Manifest -->drop down "Create application without a manifest" will work but the app won't update if there is a newer version so I have to fall back to the workaround above.
I faced the same, So whenever you update an assembly , In my case I was downgrading from CR For .Net framework 4.0 to Framework 2.0 , I replaced all referenced assemblies with the old one , The project runs fine but in order to publish
YOU MUST CLEAN WHOLE SOLUTION
then rebuild all , then publish it will solve the problem.
Thanks
I am using Visual Studio 2012 on Windows 7 and need to publish a solution consisting of two projects.
As Eduardo pointed out, marking both projects as ClickOnce, and enabling Full Trust Application resolves the problem.
I had a bit of a different problem that I was able to resolve and so I wanted to post. My issues was I was running 3 branches out of TFS. I had upgraded Telerik controls in one of my branches but not the others. Once I upgraded the Telerik controls in all 3 branches and re-published it worked and this error went away.
I was running VS2015 at the time.
It is interesting. I just redeploy the application and problem solved. Maybe a file corruption because of network.
In my version of Visual Studio 2017, version 15.6.6 (but it may been have there earlier) I found that the Application Files was not in the Right Click Exe Project and Publish, but under the Project Properties Publish Tab where you can set which of the Application Files that you want to to be put in the install.
So take out the ones that are a problem. If something is already installed on a computer where this app will be installed, there is no reason to try to reinstall it anyways, except if you need the reference for it to run. If it were to install what was already on the pc, but to a different folder it might not work. It is best to use the other applications or dll assemblies to the same location as they were previously installed.
In my case 2 exe projects in a solution had .NET target set to 4.8 and 4.6.1. After I set both to 4.8, the error stopped.
I am Using Visual Studio 2022 and the error came up.
Solved it by excluding Log4Net file in the Publish > Application Files.
and the error Stopped

Categories

Resources