WCF Client error using 'Basic128Sha256Rsa15' - wcf

I get the following error when moving from using SHA1 to SHA256 encryption via my WCF client-side config file. This is for a .NET 3.5 client running on a Windows 2003 server.
I've implemented changes related to using SHA256 for SAML data found here
Snippet from my app.config:
<customBinding>
<binding name="HAServiceBrokerSOAP11BindingHewitt">
<security defaultAlgorithmSuite="Basic128Sha256Rsa15"
Error message I receive in client error log:
System.InvalidOperationException: The binding ('CustomBinding', 'http://tempuri.org/') has been configured with a security algorithm suite 'Basic128Sha256Rsa15' that is not supported

I finally got things working. I'll post my resolution in case others land here via a search.
One thing I tried that didn't work for me but may work for someone else is to use the Common Language Runtime version 4.0. CLR version 2.0 is what is used with .NET 3.5 assemblies. Here are the lines I added to my config file just after the element:
  <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0"/>
        <supportedRuntime version="v2.0.50727"/>
   </startup>
What finally worked for me was to upgrade the code from VS 2008 .NET 3.5 to VS 2010 .NET 4.0 and recompile the entire assembly. .NET 4.0 is not supported in VS 2008. .NET 4.0 assemblies use the CLR 4.0 version.

Related

Configure Application to run on .NET 2.0 and 4.5

I am using Visual Basic Express 2010 and are trying to configure my application to run on a large variety of computers without the need of updating .NET Framework.
My current project has the following settings in app.config:
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
The target framework is .NET 2.0. One may think that, with these settings, the program should run out of the box on machines with both .NET 2.0 and 4.X
However, when I attempt to run the software on a fresh Windows 8.1 virtual machine, I run into the following error:
I'd rather not have my users install .NET 3.5 if it's not necessary. Is there a way to get past this?
Thank you all in advanced.

WIX CustomAction loading CLR 4.0 instead of 2.0

I'm trying to write a c# custom action and using .Net 2, however I can't seem to get things to work. I believe the MSI is using the wrong CLR version. I see this in the log file a few lines above where the MSI is calling my CA (line line does not appear if I comment out my CA):
SFXCA: Binding to CLR version v4.0.30319.
My custom action does not appears to load (assuming since I do not see any of the logging messages). I am using Wiz 3.6.3014.0. Is this supported or does the Windows Installer just use the latest runtime available on the machine?
Thanks
When you use WiX to create a C# custom action project, it by default creates an XML file called CustomAction.config. The purpose of this file is to instruct sfxca.dll what version of the CLR to use when running your code. The default implementation of this file looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<!--
Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that
the custom action should run on. If no versions are specified, the chosen version of the runtime
will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against.
WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility
problems with future versions of the .NET Framework runtime. It is highly recommended that you specify
only the version(s) of the .NET Framework runtime that you have tested against.
Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0.
In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies
by using the latest supported runtime, #useLegacyV2RuntimeActivationPolicy="true".
For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx
-->
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727"/>
</startup>
<!--
Add additional configuration settings here. For more information on application config files,
see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx
-->
</configuration>
Basically it's a good practice for CA's written in .NET 2.0/3.0/3.5 ( all CLR 2.0 ) to be allowed to run against 4.0 because you could come across a machine that has only 4.0 installed. Generally your code should work against 4.0 and if it doesn't, I'd fix that.
Alternatively you could update the config file to only allow running on 2.0 and then put the needed checks into the installer to make sure that this version of the CLR is infact installed.

Application built with .NET 3.5 running on machine with only .NET 4.0. How does supportedRuntime element work?

We have an application that was built using .NET 3.5. There is a situation where it will run on a machine which only has .NET 4.0 installed.
If in the application configuration file the <supportedRuntime> element is not defined, or is defined as follows
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
will the application crash on start up since .NET 3.5 and CLR v2.0.50727 are not present?
Note I understand that .NET 4.0 APIs are supposed to be compatible with .NET 3.5 ones and that a .NET 3.5 application should run in .NET 4.0. That is not the question. I am specifically asking about the <supportedRuntime> behavior.
Adding Hans Passant's comment as it seems a suitable answer.
The application will crash. To run on .NET 4.0 you need to add another supportedRuntime attribute with version="4.0".

System.Data.SQLite BadImageFormatException with NHibernate, works finewhen standalone

I tried to use NHibernate with SQLite,
version=1.0.74.0 for .NET 4 and 32 bit.
I use a 64bit WIN7, but build the application in x86 mode
(default in VS2010 express).
When I use the same SQLite as a standalone application it works fine, but when
I try to use it with NHibernate it throws BadImageFormatExcepion
I debugged a bit NHibernate and the Exception is thrown at the folllowing statement
System.Type.GetType("System.Data.SQLite.SQLiteConnection, System.Data.SQLite");
Any chances somebody knows the solution?
Is it because I use default mode in VS Express?
Do I need to specify platform using some other method?
try to download some other dll for sqlite?
I checked some other answers on SO thebest I got was
to add to my app.config this:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>
</DbProviderFactories>
</system.data>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
If VS express does not allow you to choose a platform you can try setting it up manually in .csproj file
<PlatformTarget>x86</PlatformTarget>
After building your app make sure that:
it is executed as 32 or 64 bit app depending on what you put in PlatformTarget (using Windows Task Manager or Process Explorer)
the right version of SQLite.Interop.dll is copied to the folder where you have your exe (this dll is platform dependent, so you need to copy the version corresponding to EXE platform)
Corresponding version of Visual C++ 2010 SP1 Redistributable Package is installed
Also try removing useLegacyV2RuntimeActivationPolicy from config.
From BadImageFormatException doc:
... A DLL or executable is loaded as a 64-bit assembly, but it contains
32-bit features or resources. For example, it relies on COM interop or
calls methods in a 32-bit dynamic link library. ... To address this exception, set the project's Platform target property to x86 (instead of x64 or AnyCPU) and recompile.

Is it possible to deploy a .NET 4.0 to a machine with only .NET 3.5 SP1 installed?

I am working on a WPF application that requires .NET 4.0 to run. The machines on the enterprise are all running .NET 3.5 SP1. Is it possible to deploy the application with its .NET 4 DLLs without having to install the full .NET 4 Framework on the client machines?
There are two parts of our implementation marries us to .NET 4.0
The use of the Data Grid user control (this is the easiest issue to overcome).
The use of the enableUnsecuredResponse property for my WCF binding.
<bindings>
<customBinding>
<binding name="CadsBinding">
<textMessageEncoding messageVersion="Soap11"/>
<security enableUnsecuredResponse="true" authenticationMode="UserNameOverTransport" allowInsecureTransport="true">
<secureConversationBootstrap/>
</security>
<httpTransport authenticationScheme="Basic"/>
</binding>
</customBinding>
</bindings>
Microsoft has release the following Hot Fix: A hotfix that enables WCF to send secured messages and to receive unsecured responses, and to send unsecured messages and to receive secured responses, is available for the .NET Framework 3.5 SP1 but if I am to deploy this Hot Fix to the enterprise, I might as well do that for the .NET 4.0 Client Profile and resolve all my issues then and there.
I am aware of the .NET 4.0 Client Profile installation. What I'm trying to avoid is the need to push out the installation of the framework for just my application.
My Current Thought:
It can't be done. Even if I deploy the .NET 4 DLLs that are referenced, they will still try to be handled by an older version of the CLR which won't be able to understand them.
You are going to need .NET 4, but there is the Client Profile
The .NET Framework 4 Client Profile is a subset of the .NET Framework 4 that is optimized for client applications. It provides functionality for most client applications, including Windows Presentation Foundation (WPF), Windows Forms, Windows Communication Foundation (WCF), and ClickOnce features. This enables faster deployment and a smaller install package for applications that target the .NET Framework 4 Client Profile.
This is a smaller download and smaller footprint version of the framework.
No. Those DLLs depend on assemblies registered in the GAC. Without .Net framework installed you don't get those assemblies. Why not just deploy with an installer?
No it is not possible to deploy an application which was compiled against 4.0 to a machine which only contains .Net 3.5 (any version). The 4.0 version of the runtime must be installed on the machine.
However it is possible to use Visual Studio 2010 (and 2008) to compile an assembly targeting 3.5. This would then be deployable to a machine only having the 3.5 framework. This feature is known as multi-targeting and here is a link to a tutorial on the subject
http://msdn.microsoft.com/en-us/library/bb398197.aspx
it depends on what features from 4.0 you use... some of them are just syntatic sugar and the compiler generates IL for that. For example, the new "dynamic" keyword uses the new Dynamic Language Runtime (DLR), which is only available as part of .net 4.0. So, if your app uses that, there's no other way than to install .net framework 4.0 in the machine
For me, the best idea would be to set in the project properties the target version to 3.5 (specified in the properties for your project in Visual Studio), and if there aren't any errors, you can follow this general
guidelines to test whether the app will work or not.