WorkflowInspectionServices throw me an XamlObjectWriterException in Workflow Foundation - c#

For a simple prototype, I've to display a workflow file, and show on which step we are actually.
I found a sample here: http://msdn.microsoft.com/en-us/library/ee624139.aspx
Which does almost what I need.
In this sample, all action never wait on another action. So I created myself some very dummy Activity:
public class WaitForNextCall :NativeActivity
{
public const String WaitBookmark = "WaitingStep";
#region Overrides of NativeActivity
/// <summary>
/// When implemented in a derived class, runs the activity’s execution logic.
/// </summary>
/// <param name="context">The execution context in which the activity executes.</param>
protected override void Execute(NativeActivityContext context)
{
context.CreateBookmark(WaitBookmark);
}
protected override bool CanInduceIdle
{
get
{
return true;
}
}
#endregion
}
Which seems to work. Since there I was creating my workflow directly in-code:
return new Sequence()
{
Activities =
{
new WaitForNextCall(){DisplayName = "Step one"},
new WaitForNextCall(){DisplayName = "Step Two"},
new WaitForNextCall(){DisplayName = "Step Three"},
new WaitForNextCall(){DisplayName = "Step Four"}
}
};
The only problem with that is that I only see a "Sequence" element in the workflow designer.
So I created a xaml file which describe exactily the same thing, and I load it like this:
return ActivityXamlServices.Load("Workflows/WorkflowSample.xaml") as DynamicActivity;
But then I got this exception:
System.Xaml.XamlObjectWriterException occurred
Message=Impossible de créer le type inconnu '{clr-MyTestNameSpace.UserInterface.WorkflowItems}WaitForNextCall'.
Source=System.Xaml
LineNumber=0
LinePosition=0
StackTrace:
à System.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType)
à System.Xaml.XamlWriter.WriteNode(XamlReader reader)
[...]
I double-checked, the file is present(it appears, that there is another error message when file isn't specified correctly). But it cannot find my "WaitFornextCall" class, which is used just several lines below.
I'm a little desesperate, I'm trying to understand how works Workflow foundations, but it's a little hard for now :(
Any advice will be welcome
Edit:
I tried this to read the file, I don't have any exception in my constructor, but I don't know why, some libraries I'm using(ActiPro) seems to doesn't work anymore after the load:
XamlReader reader = new XamlXmlReader("Workflows/WorkflowSample.xaml", new XamlXmlReaderSettings(){LocalAssembly = System.Reflection.Assembly.GetExecutingAssembly()});
return ActivityXamlServices.Load(reader);

I found the solution !!!!
YEAAAAAAAAAAAAAH :P
In fact the problem is that my Workflow was in the same project than my custom activity. And then visual studio doesn't indicate in which assembly the designer could found this activity, but when you read the file, this is an independant reader, which doesn't know you current assembly.
So having TWO different project, one containing the workflow, one containing activities, and then my workflow specify the assembly in which I can found the chart. Like this I can easily do a WorkflowDesigner.Load("myWorkflowHere.xaml"); without any problem!

"Workflows/WorkflowSample.xaml" probably was built against a prior version of your code.
Delete it, rebuild your solution, then recreate it.

Related

Why can I not get this Microsoft Store snippet of code to work?

Following various examples from MS and elsewhere, I have written this piece of test code...
[ComImport]
[Guid("4AEEEC08-7C92-4456-A0D6-1B675C7AC005")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IInitializeWithWindow
{
void Initialize(IntPtr hwnd);
}
and..
private async Task<bool> TestCode()
{
StoreContext Store = StoreContext.GetDefault();
StoreAppLicense licence = await Store.GetAppLicenseAsync();
bool trial = licence.IsTrial;
bool full = licence.IsActive;
IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)Store;
initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
StoreProductResult App = await Store.GetStoreProductForCurrentAppAsync();
StoreProduct p = App.Product; // Title, price
string title = p.Title;
StorePrice price = p.Price;
return true;
}
And I call it with using
bool x = TestCode().Result;
It all compiles and runs, so I presumably have all the right usings and references added. But when run, the line:
IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)Store;
stops with the exception..
Unable to cast object of type 'Windows.Services.Store.StoreContext'
to type 'IInitializeWithWindow'
and I have no clue why.
This is a C# program with a UWP wrapper creating an MSIX package.
This seems to be a pretty standard block adapted from various examples from MS.
Within VS 2019, I have associated the program with the store app.
The 'trail' and 'full' variables seem to be populating correctly.
I have called this from various locations, Constructor, random button, etc.
My questions...
Why does the cast throw an exception?
Is this an old way of doing things that no longer applies?
Does associating the package in VS 2019 to the store app make the call to IInitalizeWithWindow redundant?
How do I fix the code so that 'title' and 'price' populate correctly?
Heaps of head bashing and I finally have it working...
Considering that in the last few days there was not a combination/permutation that I did not try, I don't know really the logic of it working now, but anyway..
Within the UWP installer project I associated the project with the App in the Microsoft Store, then I removed the lines:
[ComImport]
[Guid("4AEEEC08-7C92-4456-A0D6-1B675C7AC005")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IInitializeWithWindow
{
void Initialize(IntPtr hwnd);
}
IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)Store;
initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
The rest is now working just fine. Funny as I had already associated the app with the store AND removed the offending lines. I must have done something just a little bit different this time!

WPF Cefsharp instance/object reference in class not working

I am spending too much time trying to solve this issue: i am trying to create a Core, because the project is already confusing me and it is not that big. The Core is a Class outside the main Thread. On the main Thread i named the Browser, browser :
<cefSharp:ChromiumWebBrowser x:Name="browser" x:FieldModifier="public" />
In the class i call it like this:
public class Core : MainWindow
{
public void winstenVerlies()
{
var currentdirectory = "https://www.google.nl";
this.browser.Address = currentdirectory;
}
}
I have tried numerous ways, this is the way i like it but they all give me the same message:
"object reference is not set on an instance of an object."
Any help is appreciated.
Problem solved. i researched it for weeks now, from what i can see is the problem is the root, when i use this or the object/function name when calling it, it does not get passed the root of the class, instead of the root of the project. here is how you bypass it.
pass the object trough the class.
public void winstenVerlies(ChromiumWebBrowser b)
{
var currentdirectory = "https://www.google.nl";
b.Address = currentdirectory;
}
then call it like so.
Core Menu = new Core();
Menu.winstenVerlies(browser);
Now i try'd this befor, it gave me error messages the last time, i did not trace the source of the problems.
All i know is it working now, and i am happy.
Have a nice day.

VSTO-Addins (Word, Excel) with similar functions: Outsource into own project

I am currently working on an major recode of a project I created some time ago.
It consists of two VSTO-AddIns, one for Excel and one for Word. These AddIns do have almost the same things to do, but differ in details like the data-object. In Word it is a Document, in Excel Workbooks are used. So I can't just copy and paste the code between the AddIns.
Because of that, I created the same stuff for both AddIns manually. This causes a lot of redundant code in both projects. This is a pain to maintain.
So for this refactoring I favor using a central Project both AddIns access exactly the same way.
This is how I got it working with my prior Word-AddIn as example:
Now I moved the whole Word_PropertyReadWrite into a own Project (a class library) and want to merge it with the Excel_PropertyReadWrite which exists parallel to Word_PropertyReadWrite atm. Before moving, both classes implemented IPropertyReadWrite. I think this will be needed now too, so I keep at it and also moved the interface into the new classlibrary.
This seems to work up until now, I have to create a class which redirects calls for the specific methods to the interface. These still need to exist in both AddIns parallel, but there is way less code to be maintained and the redundancy there is likely to be very hard to be terminated, though it would be nice to get rid of that, too.
But, and this is the problem I am having now, I seem to not being able to get all methods to work in this new class library.
Specific:
I can't use the Globals-Variables I need to open documents/workbooks.
I have this Open-Method, which worked before:
/// <summary>
/// Opens the file at the given path.
/// </summary>
/// <param name="Path">File's full path</param>
/// <returns>Returns success.</returns>
public bool Open(string Path)
{
//Checks, if there is already an file open. This code is not good, I know that,
//but it got the job done. This will get thrown out, since I want to get multithreating
//to work ;)
if (IsInUse)
{
log.Warn("Es ist bereits eine Datei offen und in Bearbeitung");
return false;
}
try
{
Document = Globals.ThisAddIn.Application.Documents.Open(FileName: Path,
ConfirmConversions: false, ReadOnly: false, AddToRecentFiles: false,
Revert: false, Visible: false, OpenAndRepair: true, NoEncodingDialog: false);
IsInUse = true;
Orig_FullPath = Path;
Orig_FileName = System.IO.Path.GetFileName(Path);
Orig_DirectoryPath = System.IO.Path.GetDirectoryName(Path);
log.Debug("Open war erfolgreich");
return true;
}
catch (Exception ex)
{
log.Error(string.Format("Beim Öffnen der Datei ist ein Fehler aufgetreten.\nPfad: {0}",
Path), ex);
return false;
}
}
The specific line to create problems is:
Document = Globals.ThisAddIn.Application.Documents.Open...
The use of Globals is not possible outside of the AddIn's project, since it accesses, in this case, Word itself.
Any attemp of referencing maybe ThisAddIn or Application failed until now.
The only way I see this would fit is by keeping all methods making use of this functionality in the AddIns.
But this would make the code, in my opinion, worse to maintain, because then there will be, again, more redundant code and I would tear maybe 2 or 3 methods out of the cleanly separated AddInFunctions-class. (Here is the new layout of my new class:)
So, is it possible to outsource all of these methods to an class library and if so, how is this achived?

Orleans Extension not installed

I'm starting to dive into the Orleans Streams and I'm running into an issue using ImplicitStreamSubscription. I'm building upon the QuickStart example by adding a new project that implements both the interfaces and the grains. Here is the all of the code I have so far in my grains.
[ImplicitStreamSubscription("RANDOMDATA")]
public class VSMDiscovery : Grain, IVSMDiscovery
{
public override Task OnActivateAsync()
{
Console.WriteLine("Started" + this.GetPrimaryKey());
return base.OnActivateAsync();
}
}
public interface IVSMDiscovery : IGrainWithIntegerKey
{
}
In the DevTest main, I simply send an event using
var guid = Guid.NewGuid();
//Get one of the providers which we defined in config
var streamProvider = Orleans.GrainClient.GetStreamProvider("SMSProvider");
//Get the reference to a stream
var stream = streamProvider.GetStream<int>(guid, "RANDOMDATA");
stream.OnNextAsync(1);
Everything seems to execute fine, a new grain is instantiated and OnActivateAsync is called which writes the message to the console, however I get this error.
VSM Started206d105b-d21b-496c-997a-9dac3cf370b3
Extension not installed on grain Draco.VSMConnection.VSMDiscovery attempting to invoke type Orleans.Streams.OrleansCodeGenStreamConsumerExtensionMethodInvoker from invokable Orleans.Runtime.ActivationData
Exception = Orleans.Runtime.GrainExtensionNotInstalledException: Extension not installed on grain Draco.VSMConnection.VSMDiscovery attempting to invoke type Orleans.Streams.OrleansCodeGenStreamConsumerExtensionMethodInvoker from invokable Orleans.Runtime.ActivationData
[2016-03-09 05:53:41.007 GMT 14 WARNING 103405 InsideRuntimeClient 127.0.0.1:11111] Extension not installed on grain Draco.VSMConnection.VSMDiscovery attempting to invoke type Orleans.Streams.OrleansCodeGenStreamConsumerExtensionMethodInvoker from invokable Orleans.Runtime.ActivationData for message NewPlacement Request S127.0.0.1:11111:195198808*cli/5853f180#9c59fabf->S127.0.0.1:11111:195198808*grn/EB2C0203/ac9d7a99#0e33939b #5: global::Orleans.Streams.IStreamConsumerExtension:DeliverItem()
As I mentioned, everything appears to be running ok, but having this error is very concerning. Any help would be greatly appreciated.
For me, this was caused by having a grain which had an implicit subscription attribute, but which FORGOT to subscribe to the stream in the OnActiveAsync method (which is required and is outlined in the quick start mentioned above).... not clear from the error message at all. Hope this saves someone else some pain.
You need to make sure that the "SMSProvider" stream provider is correctly specified in the config file, for both client and silo, like here: https://github.com/dotnet/orleans/blob/master/test/Tester/OrleansConfigurationForStreamingUnitTests.xml#L9

"Could not find type" error loading a form in the Windows Forms Designer

I have a .NET 2.0 windows forms app, which makes heavy use of the ListView control.
I've subclassed the ListView class into a templated SortableListView<T> class, so it can be a bit smarter about how it displays things, and sort itself.
Unfortunately this seems to break the Visual Studio Forms Designer, in both VS2005 and 2008.
The program compiles and runs fine, but when I try view the owning form in the designer, I get these Errors:
Could not find type 'MyApp.Controls.SortableListView'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built.
There is no stack trace or error line information available for this error
The variable 'listViewImages' is either undeclared or was never assigned.
At MyApp.Main.Designer.cs Line:XYZ Column:1
Call stack:
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
The line of code in question is where it is actually added to the form, and is
this.imagesTab.Controls.Add( this.listViewImages );
listViewImages is declared as
private MyApp.Controls.SortableListView<Image> listViewImages;
and is instantiated in the InitializeComponent method as follows:
this.listViewImages = new MyApp.Controls.SortableListView<Image>();
As mentioned earlier, the program compiles and runs perfectly, and I've tried shifting the SortableListView class out to a seperate assembly so it can be compiled seperately, but this makes no difference.
I have no idea where to go from here. Any help would be appreciated!
It happened to me because of x86 / x64 architecture.
Since Visual Studio (the development tool itself) has no x64 version, it's not possible to load x64 control into GUI designer.
The best approach for this might be tuning GUI under x86, and compile it for x64 when necessary.
when you added the listview, did you add it to the toolbox and then add it to the form?
No, I just edited Main.Designer.cs and changed it from System.Windows.Forms.ListView to MyApp.Controls.SortableListView<Image>
Suspecting it might have been due to the generics led me to actually finding a solution.
For each class that I need to make a SortableListView for, I defined a 'stub class' like this
class ImagesListView : SortableListView<Image> { }
Then made the Main.Designer.cs file refer to these stub classes instead of the SortableListView.
It now works, hooray!
Thankfully I am able to do this because all my types are known up front, and I'm only using the SortableListView as a method of reducing duplicate code.
I had this problem too, related to merging massive SVN changes (with conflicts) in the *.Designer.cs file. The solution was to just open up the design view graphically, edit a control (move it to the left then right) and resave the design. The *.Designer.cs file magically changed, and the warning went away on the next compilation.
To be clear, you need to fix all of the code merge problems first. This is just a work around to force VS to reload them.
I've had a problem like this (tho not the same) in the past where my control was in a different namespace to my form even tho it was in the same project. To fix it I had to add a
using My.Other.Namespace;
to the top of the designer generated code file. The annoying thing was it kept getting blown away when the designer regenerated the page.
The assembly that contains MyApp.Controls.SortableListView isn't installed in the GAC by any chance is it?
when you added the listview, did you add it to the toolbox and then add it to the form?
Perhaps you forgot to add that:
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Release all resources used.
/// </summary>
/// <param name="disposing">true if managed resources should be removed otherwise; false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
// ...
this.components = new System.ComponentModel.Container(); // Not necessarily, if You do not use
// ...
}
I have had the same problem. After removing some of my own controls of the *.Designer.cs-File the problem was solved. After going back to the original code the problem still was solved. So it seems to be a problem with the Visual Sudio cache. At the moment I cannot reproduce this problem.
If you have the problem try to emtpy the folder
C:\Users\YOURNAME\AppData\Local\Microsoft\VisualStudio\VERSION\Designer\ShadowCache
Did it work?
I had something similar - a user control was referring to a remote serice (which I couldn't guarantee being available at design time).
This post on MSDN suggested that I add
if (this.DesignMode) return;
to the Load function of the control, or in my case to the point before the WCF client was initialised. That did the trick.
So
private readonly Client _client = new Client();
becomes
private Client _client;
public new void Load()
{
if(DesignMode) return;
_client = new Client();
}
I had the same issue. In my case this issue was due to resource initialization. I moved the following code from InitializeComponent method to ctor(After calling InitializeComponent). After that this issue was resolved:
this->resources = (gcnew System::ComponentModel::ComponentResourceManager(XXX::typeid));
In my case the problem was the folder's name of my project! Why I think this:
I use SVN and in the 'trunk\SGIMovel' works perfectly. But in a branch folder named as 'OS#125\SGIMovel' I can't open the designer for a form that uses a custom control and works in the trunk folder.
Just get off the # and works nice.

Categories