Ivy
Ivy

Reputation: 887

Clickonce application runs the first time but throws an exception the second time

I have a .NET 4.0 application. On the first run, the installer runs, and the app opens normally. If you run it when it's already installed, it throws this exception:

System.BadImageFormatException was unhandled
Message: Could not load file or assembly '[my assembly]' or one of its dependencies. 
This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

The app was previously .NET 3.5, and I changed the main project and two dependencies to .NET 4. There are other references using .NET 2 and .NET 3.5, but none higher than 4. Any idea what's going on here?

Upvotes: 0

Views: 293

Answers (2)

Ivy
Ivy

Reputation: 887

The problem was that I changed my projects to build on .NET 4 (which was installed), but my program loads a different App.config from another location for updates after it starts the first time.That config file contained

<startup>
  <supportedRuntime version="v2.0.50727"/>
</startup>

instead of

<startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>

which caused my app to load the 3.5 runtime when it started instead of using .NET 4.

Upvotes: 0

Scott Wylie
Scott Wylie

Reputation: 4735

Not sure how it works the first time but based on the error message, it really looks like your client machine does not have .NET 4 framework installed (not sure if you need just the client version of .NET 4 or the full version).

Upvotes: 1

Related Questions