I am rehosting WF4 workflow designer.
For a state machine, I don't know how to provide a "FinalState" via sapt:ToolboxItemWrapper in XAML.
There is no FinalState class, only a State class for "regular" states. State class has a IsFinal property, so I guess it has to be set in order to become a "FinalState".
I tried deriving my own FinalState class from State that would set IsFinal in the constructor, but it doesn't work as State is sealed.
So how can I provide FinalState from XAML?
There actually is a FinalState class, just in a different assembly. So to add state machine use:
<Window.Resources>
<sys:String x:Key="AssemblyName">System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</sys:String>
<sys:String x:Key="SACPAssemblyName">System.Activities.Core.Presentation, Version=4.0.0.0, Culture=neutral, PublicKeyToken="31bf3856ad364e35"</sys:String>
</Window.Resources>
<sapt:ToolboxCategory CategoryName="State Machine">
<sapt:ToolboxItemWrapper AssemblyName="{StaticResource AssemblyName}">
<sapt:ToolboxItemWrapper.ToolName>
System.Activities.Statements.Statemachine
</sapt:ToolboxItemWrapper.ToolName>
</sapt:ToolboxItemWrapper>
<sapt:ToolboxItemWrapper AssemblyName="{StaticResource AssemblyName}">
<sapt:ToolboxItemWrapper.ToolName>
System.Activities.Statements.State
</sapt:ToolboxItemWrapper.ToolName>
</sapt:ToolboxItemWrapper>
<sapt:ToolboxItemWrapper AssemblyName="{StaticResource SACPAssemblyName}">
<sapt:ToolboxItemWrapper.ToolName>
System.Activities.Core.Presentation.FinalState
</sapt:ToolboxItemWrapper.ToolName>
</sapt:ToolboxItemWrapper>
</sapt:ToolboxCategory>
Related
Having an issue getting the correct logger via DI, at least that is what it seems.
Here is the code in Program.cs:
var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
logger.Info("Service Init");
logger.Info($" Log Level - Debug: {logger.IsEnabled(NLog.LogLevel.Debug)} Trace: {logger.IsEnabled(NLog.LogLevel.Trace)}");
try
{
var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
//builder.Logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
builder.Host.UseNLog();
builder.Services.AddControllersWithViews();
var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
}
catch (Exception exc)
{
// NLog: catch setup errors
logger.Error(exc, "Stopped program because of exception");
throw;
}
finally
{
NLog.LogManager.Shutdown();
}
When I run the app the initial log information (logged to file) shows the correct values for the log level, for example if I set minlog in NLog.config to "Debug" then the value shows true in the log and similarly if I change it to "Trace" the log shows appropriately.
In a controller when I try and log the same information using the below, they are always false:
_logger.Info($"Log Level - Debug: {_logger.IsEnabled(NLog.LogLevel.Debug)} Trace: {_logger.IsEnabled(NLog.LogLevel.Trace)}");
Additional notes:
In the controller, any controller, no logs are being written to the configured log file. Only thing making it to the configured log file is from the logger instance created in Program.cs.
I have a number of other solutions using the prior generation setup where you have Program.cs and Startup.cs. Those solutions also use CreateHostBuilder(args).Build() instead of WebApplication.CreateBuilder(args). The prior generation setup works as expected.
NLog.Exensions.Logging and NLog.Web.AspNetCore versions are both 5.2.1
Home Controller
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
And more notes:
I commented out the logger in Program.cs and also made use of this to obtain the configuration from appsettings.config. I've also made use of this when I create the instance of logger in Program.cs and so I know the configuration is correct:
builder.Host.UseNLog(new NLogAspNetCoreOptions() { LoggingConfigurationSectionName = "NLog" });
Regardless of creating logger instance in Program.cs, when I do a QuickWatch of the logger instance passed into a controller constructor I see the the below. The provider type looks good, NLog, but where it is picking up a configuration I'm at a loss.
Finally, as per a suggestion from Rolf, I add this in Program.cs to see what NLog was doing, unfortunately it didn't given much detail. No configuration information listed:
NLog.Common.InternalLogger.LogLevel = NLog.LogLevel.Trace;
NLog.Common.InternalLogger.LogToConsole = true;
NLog.Common.InternalLogger.LogFile = #"c:\temp\nlog-debug.txt";
The log output looks like this:
2023-01-08 08:58:50.5328 Debug ScanAssembly('NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
2023-01-08 08:58:50.6446 Debug ScanAssembly('NLog.Web.AspNetCore, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
2023-01-08 08:58:50.6610 Trace Assembly 'NLog.Web.AspNetCore, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' will be hidden in callsite stacktrace
2023-01-08 08:58:50.9908 Debug Hide assemblies for callsite
2023-01-08 08:58:50.9914 Debug ScanAssembly('NLog.Extensions.Logging, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
2023-01-08 08:58:50.9914 Trace Assembly 'NLog.Extensions.Logging, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' will be hidden in callsite stacktrace
2023-01-08 08:58:50.9914 Trace Assembly 'Microsoft.Extensions.Logging.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' will be hidden in callsite stacktrace
2023-01-08 08:58:50.9914 Trace Assembly 'Microsoft.Extensions.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' will be hidden in callsite stacktrace
2023-01-08 08:58:51.0219 Trace ParseNLogConfig
So I feel like I should delete this post to keep people from chasing down the wrong path ;)
Nevertheless, the solution was simple, and a very dumb mistake on my part. In nlog.config I had something like this:
<logger name="<MyNameSpace>.*" maxLevel="Info" final="true" />
...where <MyNameSpace> is simply that, the namespace of the project.
I had something similar in another solution but it was less aggressive <MyNameSpace>.<SubNameSpace>.
Basically I was eliminating from the logs junk I didn't want, but I went to far.
Anyway, lesson is be careful with your rule because you will take the "applicable logger" out of the equation leaving you wondering why your logger isn't looking like or performing like you think it should.
I have an ASP.NET MVC application for which I've configured sessions in the web.config as follows:
<!--
If you are deploying to a cloud environment that has multiple web server instances,
you should change session state mode from "InProc" to "Custom". In addition,
change the connection string named "DefaultConnection" to connect to an instance
of SQL Server (including SQL Azure and SQL Compact) instead of to SQL Server Express.
-->
<sessionState customProvider="DefaultSessionProvider" mode="InProc" timeout="65">
<providers>
<add name="DefaultSessionProvider"
type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="DefaultConnection" />
</providers>
</sessionState>
FYI, our production environment has four app servers which is I assume why the DefaultSessionProvider was set (by someone else).
I'm using a SessionHelper class to store information in the session:
public class SessionHelper : ISessionHelper
{
private readonly HttpContextBase context;
public SessionHelper(HttpContextBase context)
{
this.context = context;
}
public int? GetUserId()
{
return getSessionValue<int?>(USER_ID_KEY);
}
private T getSessionValue<T>(string key)
{
var value = context.Session[key];
if (value == null)
{
return default(T);
}
return (T)value;
}
}
I'm using Ninject to inject HttpContextBase like so:
kernel.Bind<HttpContextBase>().ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)).InTransientScope();
What I'm seeing is that before the timeout of 65 mins which I have set in the web.config, the session variables are null. I also noticed Session_End() in my Global.asax.cs being called.
I've done some research and the information I found regarding sessions ending prematurely seems to be focused on things that would affect all users like files being changed in the bin directory causing the app pool to restart. Things like that. I believe my issue is on a session-by-session basis.
Why is my session ending before I want it to? Thanks in advance.
In my asp.net project there are class libraries called DataLayer, BusinessLayer, ModelLayer and the Web application project. i have added a WCF webservices project to the solution. In the WCF i have implemented a simple method
public string GetName(string name)
{
var Garage = new GarageView_ML();
{
Garage.GarageName = name;
};
return new GarageView_DL().GetNameDL(Garage);
}
In the DataLayer class GarageView_DL i have implemented the following method
public string GetNameDL(GarageView_ML ml)
{
return "OK" + ml.GarageName;
}
The "return" in the line return new GarageView_DL().GetNameDL(Garage); is underlined with dark blue color giving the error
The type 'System.Web.UI.Page' is defined in an assembly that is not
referenced. You must add a reference to assembly 'System.Web,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'. E:\TestProjects\Myapp\WebApplication1\MVCS_WCFService\Service1.cs 42 13 MVCS_WCFService
I have tried adding the System.web reference but it didn't work. Any help is apprciated to solve the issue. thanks in advance.
ps: i can access other layers(Model and business) without any issue. Error comes only when accessing the datalayer.
I have an interface:
namespace IF.Model
{
public interface IAllocationGroupRepository
{
}
}
and a class the implements that interface:
using IF.Model;
namespace IF.Repository
{
public class AllocationGroupRepository : IAllocationGroupRepository
{
}
}
In a Unity Framework call, I can .RegisterType() in the code for both of them:
IUnityContainer container = new UnityContainer();
container.RegisterType<IAllocationItemRepository, AllocationItemRepository>();
IAllocationItemRepository _allocationItemRepository = container.Resolve<IAllocationItemRepository>();
and .Resolve() works and gives me a new AllocationItemRepository object.
BUT, when I try to call Resolve and the mapping lives in the app.config file, I get this error:
"The current type, IF.Model.IAllocationItemRepository, is an interface and cannot be constructed. Are you missing a type mapping?"
Here is what my app.config file looks like:
<unity>
<containers>
<container>
<types>
<type
type="IF.Model.IAllocationGroupRepository, IF.Model"
mapTo="IF.Repository.AllocationGroupRepository, IF.Repository" />
</types>
</container>
</containers>
</unity>
here is what the code looks like trying to call .Resolve() using what's in the App.config file:
IUnityContainer container = new UnityContainer();
UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
section.Containers.Default.Configure(container);
IAllocationItemRepository _allocationItemRepository = container.Resolve<IAllocationItemRepository>();
as you can see, this is pretty basic stuff. Given an interface, resolve it to the class. It works when doing it inline, but fails when trying to do it from the app.config file.
What am I missing here?
Thanks,
Mike
Try using aliases which call for the namespace as one of the parameters.
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<alias alias="IAllocationGroupRepository" type="IF.Model.IAllocationGroupRepository, IF.Model, Version=1.0.0.0, Culture=neutral"/>
<alias alias="AllocationGroupRepository" type="IF.Repository.AllocationGroupRepository, IF.Repository, Version=1.0.0.0, Culture=neutral"/>
<container>
<register type="IAllocationGroupRepository" mapTo="AllocationGroupRepository"/>
</container>
</unity>
However, why are you putting your repository interfaces in your model namespace? Would you, as a developer looking at that code for the first time, expect to find an IRepository interface in the Model namespace or the Repository namespace?
I'm assuming you a have unity reference, then you need to define your section name and its library. like so:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="mySectionName" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
</configSections>
<mySectionName>
<typeAliases>
...
I am using the traditional Asp.Net website in which I am using the System.Web.Routing module. I want to find the way in which I know that the routing http modules is loaded or not?
All you need to know is the module's name as you have it configured in your web.config file
for example mine is named: "UrlRoutingModule" as you can see from this snippet here (formatted for StackOverflow):
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule, System.Web.Routing,
Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
once you have that, all you need to do is check the application's Modules property (which is of type HttpModuleCollection for your module's name and verify that it's not null. If you want to do some extra checking you can check the type of the object too (not shown).
// From Global.asax.cs
protected void Application_Start(object sender, EventArgs e)
{
if (Modules.AllKeys.Contains("UrlRoutingModules")
&& Modules["UrlRoutingModule"] != null)
{
// the module is loaded
}
}