Different versions of ClickOnce application cause crash due to missing original UI.exe file

0

I´m having a problem with ClickOnce releases:

  • We need three versions of a program installed via ClickOnce on every machine, each having different settings: Production, Pilot and Test
  • What we do is use a self programmed release manager that deploys every version in a different network drive location using MSBuild
  • Installation of every version works out fine, but program crashes when being run.
  • The ApplicationName is changed while running MSBuild and I have found that the application is still looking for the original UI.exe whilst the name of the Application has changed to e.g. UITest.exe
  • If I copy the UI.exe to the installation folder and then run UITest.exe the program works as it should.

What am I missing? How can I get rid of the need of the original UI.exe?

Background Infos:

To be able to release three different versions via MSBuild we use an additional ".target" file that is implemented in UI.csproj after the build property groups like this:

<Import Project="CustomBuild.targets" />

The CustomBuild.targets file looks like this:

<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <PublishType>none</PublishType>
  </PropertyGroup>
  <Choose>
    <When Condition="'$(PublishType)' == 'production'">
      <PropertyGroup>
        <PublishUrl>\\netapp1\users\ClickOnce\Production\</PublishUrl>
        <InstallUrl>\\netapp1\users\ClickOnce\Production\</InstallUrl> 
        <PublishDir>\\netapp1\users\ClickOnce\Production\</PublishDir> 
        <ProductName>UI Production</ProductName>
        <AssemblyName>UIProd</AssemblyName> -- AssemblyName is changed here
        <UIExchangeSettingsPath>..\_UIExchangeSettings\Prod</UIExchangeSettingsPath>
    </PropertyGroup>
    </When>
    <When Condition=" '$(PublishType)' == 'pilot' ">
      <PropertyGroup>
        <PublishUrl>\\netapp1\users\ClickOnce\Pilot\</PublishUrl>
        <InstallUrl>\\netapp1\users\ClickOnce\Pilot\</InstallUrl>
        <PublishDir>\\netapp1\users\ClickOnce\Pilot\</PublishDir> 
        <ProductName>UI Pilot</ProductName>
        <AssemblyName>UIPilot</AssemblyName> -- AssemblyName is changed here
        <UIExchangeSettingsPath>..\_UIExchangeSettings\Pilot</UIExchangeSettingsPath>
      </PropertyGroup>
    </When>
    <When Condition=" '$(PublishType)' == 'test' ">
      <PropertyGroup>
        <PublishUrl>\\netapp1\users\ClickOnce\Test\</PublishUrl>
        <InstallUrl>\\netapp1\users\ClickOnce\Test\</InstallUrl>
        <PublishDir>\\netapp1\users\ClickOnce\Test\</PublishDir> 
        <ProductName>UI Test</ProductName>
        <AssemblyName>UITest</AssemblyName> -- AssemblyName is changed here
        <UIExchangeSettingsPath>..\_UIExchangeSettings\Test</UIExchangeSettingsPath>
      </PropertyGroup>
    </When>
  </Choose>
</Project>

Then the MSBuild Process is called within a batch file like this:

@echo off

set branch=%1
set publishtype=%2

echo Rebuilding UI project and publishing as new %publishtype% version...
>output.txt (
  "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin\MSBuild.EXE" "C:\Projects\%branch%\UI" /p:SolutionDir="C:\Projects\%branch%\\" /p:PlatformTarget=x86 /p:Configuration=Release /p:PublishType=%publishtype% /t:rebuild /t:publish 
)

When running the installed programs they crash and show the following exceptions in the windows event log:

Log Name:      Application
Source:        .NET Runtime
Date:          11.11.2020 10:02:58
Event ID:      1026
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      vw8-te-012.HOPPE-BMT.intranet
Description:
Application: UIProd.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
   at System.Reflection.RuntimeAssembly._nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.RuntimeAssembly.nLoad(System.Reflection.AssemblyName, System.String, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(System.Reflection.AssemblyName, System.Security.Policy.Evidence, System.Reflection.RuntimeAssembly, System.Threading.StackCrawlMark ByRef, IntPtr, Boolean, Boolean, Boolean)
   at System.Reflection.Assembly.Load(System.Reflection.AssemblyName)
   at System.Windows.Navigation.BaseUriHelper.GetLoadedAssembly(System.String, System.String, System.String)
   at MS.Internal.AppModel.ResourceContainer.GetResourceManagerWrapper(System.Uri, System.String ByRef, Boolean ByRef)
   at MS.Internal.AppModel.ResourceContainer.GetPartCore(System.Uri)
   at System.IO.Packaging.Package.GetPartHelper(System.Uri)
   at System.IO.Packaging.Package.GetPart(System.Uri)
   at System.IO.Packaging.PackWebResponse+CachedResponse.GetResponseStream()
   at System.IO.Packaging.PackWebResponse.GetResponseStream()
   at System.IO.Packaging.PackWebResponse.get_ContentType()
   at MS.Internal.WpfWebRequestHelper.GetContentType(System.Net.WebResponse)
   at MS.Internal.WpfWebRequestHelper.GetResponseStream(System.Net.WebRequest, MS.Internal.ContentType ByRef)
   at System.Windows.ResourceDictionary.set_Source(System.Uri)
   at System.Windows.Baml2006.WpfSharedBamlSchemaContext+<>c.<Create_BamlProperty_ResourceDictionary_Source>b__342_0(System.Object, System.Object)
   at System.Windows.Baml2006.WpfKnownMemberInvoker.SetValue(System.Object, System.Object)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Xaml.XamlMember, System.Object, System.Object)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(System.Object, System.Xaml.XamlMember, System.Object)

Exception Info: System.Windows.Markup.XamlParseException
   at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)
   at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
   at System.Windows.Application.LoadComponent(System.Object, System.Uri)
   at UI.App.InitializeComponent()
   at UI.App.Main()

and

Log Name:      Application
Source:        Application Error
Date:          11.11.2020 10:02:58
Event ID:      1000
Task Category: (100)
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      vw8-te-012.HOPPE-BMT.intranet
Description:
Faulting application name: UIProd.exe, version: 1.0.0.0, time stamp: 0x5faba858
Faulting module name: KERNELBASE.dll, version: 6.3.9600.17031, time stamp: 0x53088860
Exception code: 0xe0434352
Fault offset: 0x00014dbd
Faulting process ID: 0x3594
Faulting application start time: 0x01d6b80972f79f7d
Faulting application path: C:\Users\c.nowottny\AppData\Local\Apps\2.0\XNQORKVG.2DT\5A4N7BAY.11G\uipr..tion_e9badd1d426758be_0001.0001_0a1650216431b128\UIProd.exe
Faulting module path: C:\Windows\SYSTEM32\KERNELBASE.dll
Report ID: b1090c1f-23fc-11eb-82ef-0050568fb707
Faulting package full name: 
Faulting package-relative application ID: 
c#
msbuild
clickonce
asked on Stack Overflow Nov 11, 2020 by Chris • edited Nov 11, 2020 by Chris

1 Answer

0

Turns out it was a reference to a resource dictionary in App.xaml causing the problem.

Wrong implementation:

<ResourceDictionary Source="pack://application:,,,/UI;component/Resources/PlcBuildResources.xaml" />

Corrected implementation:

<ResourceDictionary Source="../Resources/PlcBuildResources.xaml"/>

Lesson learned: Be careful when referencing resource dictionaries or other files using the assembly name in the reference. If the assembly name is changed when building via MSBuild as in my case, the referenced file will not be found and cause the application to crash.

answered on Stack Overflow Nov 11, 2020 by Chris

User contributions licensed under CC BY-SA 3.0