Description
I'm creating Windows Workflow Foundation Nuget Library. When I build the project I got the below warning.
Could not compile workflow expressions because file 'file:///C:\Users\iyhammad\.nuget\packages\system.buffers\4.5.0\ref\net45\System.Buffers.dll' has an incorrect format. Workflows in this project may still run, if they do not require expression compilation. If the file is a platform-specific library or executable, consider building the project using MSBuild.exe from a command prompt of the targeted platform.
If I ignore this warning and use the Nuget library in a Windows Workflow Foundation Service application, I can't open the Workflow designer once I use any component from the library. I always get the below exception in design time.
System.Xaml.XamlObjectWriterException: 'The invocation of the constructor on type 'KanooIT.Bpm.WorkflowLibrary.InitiateHumanWorkflow' that matches the specified binding constraints threw an exception.' Line number '116' and line position '32'. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Buffers, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at XamlStaticHelperNamespace._XamlStaticHelper.Load(String assemblyNameVal)
at XamlStaticHelperNamespace._XamlStaticHelper.LoadAssemblies()
at XamlStaticHelperNamespace._XamlStaticHelper.get_AssemblyList()
at XamlStaticHelperNamespace._XamlStaticHelper.get_SchemaContext()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Activities.XamlIntegration.ActivityXamlServices.GetXamlSchemaContext(Assembly assembly, String helperClassName)
at System.Activities.XamlIntegration.ActivityXamlServices.InitializeComponent(Type componentType, Object componentInstance)
at KanooIT.Bpm.WorkflowLibrary.InitiateHumanWorkflow.BeforeInitializeComponent(Boolean& isInitialized)
at KanooIT.Bpm.WorkflowLibrary.InitiateHumanWorkflow.InitializeComponent()
at KanooIT.Bpm.WorkflowLibrary.InitiateHumanWorkflow..ctor()
--- End of inner exception stack trace ---
at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
at System.Xaml.XamlObjectWriter.Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
at System.Xaml.XamlObjectWriter.WriteStartMember(XamlMember property)
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at System.Activities.Presentation.Xaml.ErrorTolerantObjectWriter.XamlFragment.WriteTo(XamlWriter writer, Boolean parentHasError)
at System.Activities.Presentation.Xaml.ErrorTolerantObjectWriter.ActivityFragment.WriteTo(XamlWriter writer, Boolean parentHasError)
at System.Activities.Presentation.Xaml.ErrorTolerantObjectWriter.XamlFragment.WriteTo(XamlWriter writer, Boolean parentHasError)
at System.Activities.Presentation.Xaml.ErrorTolerantObjectWriter.ActivityFragment.WriteTo(XamlWriter writer, Boolean parentHasError)
at System.Activities.Presentation.Xaml.ErrorTolerantObjectWriter.XamlFragment.WriteTo(XamlWriter writer, Boolean parentHasError)
at System.Activities.Presentation.Xaml.ErrorTolerantObjectWriter.CompleteLoad()
at System.Activities.Presentation.Xaml.ErrorTolerantObjectWriter.WriteEndObject()
at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
at System.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter)
at Microsoft.Activities.Presentation.Xaml.WorkflowDesignerXamlHelper.DeserializeString(String text, DeserializationMode mode, IList`1& loadErrors, Dictionary`2& sourceLocations)
at Microsoft.Activities.Presentation.Xaml.WorkflowDesignerXamlHelper.DeserializeString(String text, IList`1& loadErrors, Dictionary`2& sourceLocations)
at System.Activities.Presentation.WorkflowDesigner.Load()
After build, I found the file System.Buffers.dll with file version 4.6.26515.6 in bin of the NuGet package and the application as well.
I've added the below auto generated binding redirect in the web.config of the Workflow Service Application
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="CC7B13FFCD2DDD51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0"/>
</dependentAssembly>
More information:
The NuGet Package and the solution is build against 4.7.2
Windows 10 Build: 17134.112
Visual Studio 2017. 15.7.3
.NET SDK: 2.1.300