Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

QMSAPI v10SR5 vs V11SR2 ServiceKeyBehaviorExtensionElement


Using QMSAPI from V10SR5 I built an app that was able to inject a service key using the following in my app.config

<behaviorExtensions>
        <add name="serviceKeyBehavior" type="TerraTechnology.AnalyticModuleLoader.ServiceKeyBehaviorExtensionElement, AnalyticModuleLoader"/>
</behaviorExtensions>

Note that the "type=..." is NOTa fully qualified assembly name; it does not have Version=xxx, Culture=xxx, PublicKeyToken=xxx.

It appears that when I use v11SR2 and I try to use the above abbreviated assembly qualifier I get an error:

An exception occurred: An error occurred creating the configuration section handler for system.serviceModel/behaviors: Extension element 'serviceKeyBehavior' cannot be added to this element.  Verify that the extension is registered in the extension collection at system.serviceModel/extensions/behaviorExtensions.

If I use a fully qualified assembly description in the app.config

<behaviorExtensions>
        <add name="serviceKeyBehavior" type="TerraTechnology.AnalyticModuleLoader.ServiceKeyBehaviorExtensionElement, AnalyticModuleLoader, Version=4.2.4716.29448, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>

I do not get an error.

I am wondering if there was a change in the way QMSAPI tries to create an instance of the type specified in the behaviorExtensions between v10 and v11.

1 Solution

Accepted Solutions
Not applicable
Author

Bug in .NET 3.5

The behaviorExtension for QMSAPI serviceKeyBehavior must be be strongly typed, i.e. must contain Version/Culture/PublicKeyToken that exactly match the assembly. No extra spaces allowed. Version etc must be specified.

  <behaviorExtensions>
    <add name="serviceKeyBehavior" type="MyNamespace.ServiceKeyBehaviorExtensionElement, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
  </behaviorExtensions>

This causes problems when the version of the assembly is autoincremented during assembly compile/build.

Fixed in .NET 4.0. Version/Culture/PublicKeyToken may be dropped so that the config no longer needs the autoincremented value of the version.

  <behaviorExtensions>
    <add name="serviceKeyBehavior" type="MyNamespace.ServiceKeyBehaviorExtensionElement, MyAssembly"/>
  </behaviorExtensions>

View solution in original post

2 Replies
Not applicable
Author

Invoke the folloiwng before any QMSAPI calls. It will update the in-memory configuration information to the current assembly version and avoid the exception in this discussion.

public UpdateServeKeyBehaviorType()
{
  Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  ServiceModelSectionGroup smGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);
  ExtensionElementCollection extensions = ServiceModelSectionGroup.GetSectionGroup(configuration).Extensions.BehaviorExtensions;
  ExtensionElement behavior = extensions["serviceKeyBehavior"];
  //myNameSpace.ServiceKeyBehaviorExtensionElement, myAssembly, Version=1.0.4723.26787, Culture=neutral, PublicKeyToken=null
  string oldType = behavior.Type;
  string newType = oldType.Substring(0, oldType.IndexOf("Version=") + 😎 + AssemblyVersion() + oldType.Substring(oldType.IndexOf(", Culture"));
  behavior.Type = newType;
  configuration.Save();
}

public string AssemblyVersion()
{
  string[] pieces = Assembly.GetEntryAssembly().FullName.Split(new char[] { '=', ',' });
  return (pieces.Count() > 2 ? pieces[2] : string.Empty);
}

Not applicable
Author

Bug in .NET 3.5

The behaviorExtension for QMSAPI serviceKeyBehavior must be be strongly typed, i.e. must contain Version/Culture/PublicKeyToken that exactly match the assembly. No extra spaces allowed. Version etc must be specified.

  <behaviorExtensions>
    <add name="serviceKeyBehavior" type="MyNamespace.ServiceKeyBehaviorExtensionElement, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
  </behaviorExtensions>

This causes problems when the version of the assembly is autoincremented during assembly compile/build.

Fixed in .NET 4.0. Version/Culture/PublicKeyToken may be dropped so that the config no longer needs the autoincremented value of the version.

  <behaviorExtensions>
    <add name="serviceKeyBehavior" type="MyNamespace.ServiceKeyBehaviorExtensionElement, MyAssembly"/>
  </behaviorExtensions>