I'm trying to build a WP 8.0 project in code. I'm using the Project class and the Build method, source code is available here.
The code worked on Windows 8 using VS 2012, but while I upgraded to Windows 8.1 and VS2013, it stopped working. I know that Microsoft changed and removed the Build framework from .NET in VS, but I am still not sure why it happens and how can I fix it.
The error:
C:\Program Files
(x86)\MSBuild\Microsoft\WindowsPhone\v8.0\Microsoft.WindowsPhone.Common.targets(75,5):
error MSB4127: The "GetSilverlightFrameworkPath" task could not be
instantiated from the assembly "C:\Program Files
(x86)\MSBuild\Microsoft\WindowsPhone\v8.0\Microsoft.Silverlight.WindowsPhone.Build.Tasks.dll".
Please verify the task assembly has been built using the same version
of the Microsoft.Build.Framework assembly as the one installed on your
computer and that your host application is not missing a binding
redirect for Microsoft.Build.Framework. Unable to cast object of type
'Microsoft.Silverlight.Build.Tasks.GetSilverlightFrameworkPath' to
type 'Microsoft.Build.Framework.ITask'.C:\Program Files
(x86)\MSBuild\Microsoft\WindowsPhone\v8.0\Microsoft.WindowsPhone.Common.targets(75,5):
error MSB4060: The "GetSilverlightFrameworkPath" task has been
declared or used incorrectly, or failed during construction. Check the
spelling of the task name and the assembly name.
UPDATE:
By the way the WP 8.0 is compiled using VS2013, the problem occurs when trying to build it from code.
You are getting this error because Microsoft.Silverlight.WindowsPhone.Build.Tasks.dll is the assembly which holds GetSilverlightFrameworkPath, e.g. in the Silverlight 4 and 5 SDK:
// Decompiled with JetBrains decompiler
// Type: Microsoft.Silverlight.Build.Tasks.GetSilverlightFrameworkPath
// Assembly: Microsoft.Silverlight.Build.Tasks, Version=9.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// MVID: 2E9B62C4-1C0C-4AAD-8CBE-F7E074602879
// Assembly location: C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v5.0
//omitted for brevity
namespace Microsoft.Silverlight.Build.Tasks
{
public sealed class GetSilverlightFrameworkPath : Task
{
private const string SDKAssemblyFoldersExRegKey = "v5.0\\AssemblyFoldersEx";
public const string SDKLibrariesRegKey = "v5.0\\AssemblyFoldersEx\\Silverlight SDK Client Libraries";
public const string SDKRuntimeInstallPathRegKey = "SOFTWARE\\Microsoft\\Microsoft SDKs\\Silverlight\\v5.0\\ReferenceAssemblies";
public string RegistryBase { get; set; }
public string SilverlightPath { get; set; }
public string[] SilverlightSDKPaths { get; set; }
public string SilverlightRuntimeVersion { get; set; }
public override bool Execute()
{
//omitted for brevity
}
private string GetSilverlightPath()
{
//omitted for brevity
}
private string GetSDKRuntimeVersion()
{
//omitted for brevity
}
private string[] GetAllSilverlightSDKPaths()
{
//omitted for brevity
}
}
}
However, its implementation in WP v8.0 seems quite different indeed:
// Decompiled with JetBrains decompiler
// Type: Microsoft.Silverlight.Build.Tasks.GetSilverlightFrameworkPath
// Assembly: Microsoft.Silverlight.WindowsPhone.Build.Tasks, Version=9.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// MVID: 899BFFD0-786C-472A-8935-576EED0F4F90
// Assembly location: C:\Program Files (x86)\MSBuild\Microsoft\WindowsPhone\v8.0\Microsoft.Silverlight.WindowsPhone.Build.Tasks.dll
//omitted for brevity
namespace Microsoft.Silverlight.Build.Tasks
{
public sealed class GetSilverlightFrameworkPath : Task
{
public string RegistryBase { get; set; }
public string RuntimePathRegistryKey { get; set; }
public string RuntimeVersionRegistryKey { get; set; }
public string AdditionalRegistryBasePaths { get; set; }
public string SilverlightPath { get; set; }
public string[] SilverlightSDKPaths { get; set; }
public string SilverlightRuntimeVersion { get; set; }
public override bool Execute()
{
// omitted for brevity
}
private string GetSilverlightPath()
{
// omitted for brevity
}
private string GetSDKRuntimeVersion()
{
// omitted for brevity
}
internal string[] GetAllSilverlightSDKPaths()
{
// omitted for brevity
}
}
Therefore, it is quite natural that things do not work.
What you need to do is check that you are referencing the same SDK versions in all your projects.
The Task you are trying to instantiate during the build is in SL SDK 5 whereas currently for some reason the build process is trying to use the WP8.0 SDK.
Moreover, the code you referenced is part of a csproj that references Toolset 12.0:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Are you certain that is desired?
This info might also be relevant to you.
If you provide more info on your actual project, it can probably be easily fixed. Right now, it is a bit difficult to judge how everything is set up.
Related
when i put fluent validators in asp.net core client side validation project exactly work
but when i put validator in class library not work
My model and validator in class library :
using FluentValidation;
namespace ClassLibrary1
{
public class Person
{
public string Name { get; set; }
public string Family { get; set; }
public int Age { get; set; }
}
public class PersonValidator : AbstractValidator<Person>
{
public PersonValidator()
{
RuleFor(c => c.Name).NotEmpty().WithMessage("Name Is Empty");
}
}
}
In program.cs file :
services.AddFluentValidationAutoValidation(M =>
{
M.DisableDataAnnotationsValidation = true;
}).AddFluentValidationClientsideAdapters()
.AddValidatorsFromAssemblyContaining<PersonValidator>();
I can't reproduce the issue, and it works in my side, I will show my test steps.
Steps
my project structure.
The person.cs code same as yours
The program.cs code same as yours
My test method in Controller.
[HttpPost]
[Route("Test")]
public IActionResult Test([FromBody]Person model)
{
if (!ModelState.IsValid) //<----Validate here
{
return new BadRequestObjectResult(ModelState);
}
return Ok();
//Other Code..
}
Test result and it works.
I found the solution.
When the class library is nullable, the client-side validation in ASP.NET Core does not work.
Solution:
Remove <Nullable>enable</Nullable> from the *.csproj
Define nullable property:
public string? name{get;set}
I need to store a NodaTime LocalDateTime in an Akavache cache.
I've created a simple app which takes the following class and stores/retrieves it in/from an Akavache cache:
public class TestModel
{
public string Name { get; set; }
public LocalDateTime StartDateTimeLocal {get; set;}
public DateTime StartDateTimeUtc {get;set;}
}
When this is stored in and retrieved from the cache, the StartDateTimeLocal property hasn't been populated.
It seems that Akavache isn't aware of how to serialise/deserialize a LocalDateTime.
Is it possible to register types with Akavache or supply a custom serialisation for unknown types?
Console application to demonstrate it:
using Akavache;
using NodaTime;
using System;
using System.Reactive.Linq;
namespace AkavacheNodaTimeCore
{
class Program
{
static TestModel BeforeModel;
static TestModel AfterModel;
static void Main(string[] args)
{
// Note that we're using Akavache 6.0.27, to match the version we're using in our live system.
BlobCache.ApplicationName = "AkavacheNodaTimeCore";
BlobCache.EnsureInitialized();
BeforeModel = new TestModel()
{
StartLocalDateTime = LocalDateTime.FromDateTime(DateTime.Now),
StartDateTime = DateTime.UtcNow,
};
Console.WriteLine($"Before:LocalDateTime='{BeforeModel.StartLocalDateTime}' DateTime='{BeforeModel.StartDateTime}'");
CycleTheModels();
Console.WriteLine($"After: LocalDateTime='{AfterModel.StartLocalDateTime}' DateTime='{AfterModel.StartDateTime}'");
Console.WriteLine("Note that Akavache retrieves DateTimes as DateTimeKind.Local, so DateTime before and after above will differ.");
Console.WriteLine("Press any key to continue.");
var y = Console.ReadKey();
}
/// <summary>
/// Puts a model into Akavache and retrieves a new one so we can compare.
/// </summary>
static async void CycleTheModels()
{
await BlobCache.InMemory.Invalidate("model");
await BlobCache.InMemory.InsertObject("model", BeforeModel);
AfterModel = await BlobCache.InMemory.GetObject<TestModel>("model");
}
}
}
TestModel class:
using NodaTime;
using System;
namespace AkavacheNodaTimeCore
{
public class TestModel
{
public string Name { get; set; }
public LocalDateTime StartLocalDateTime { get; set; }
public DateTime StartDateTime {get;set;}
}
}
I have added a Git repo with the above in a console application which demonstrates the problem.
You need to configure the JsonSerializerSettings that Akavache uses with Json.NET. You'll need a reference to NodaTime.Serialization.JsonNet, at which point you can create a serializer settings instance, configure it for Noda Time, then add that as a dependency in Splat (which Akavache uses). I haven't used Splat before, so it's possible that this isn't the right way of doing it, but it works with your example:
using Newtonsoft.Json;
using NodaTime.Serialization.JsonNet;
using Splat;
...
// This should be before any of your other code.
var settings = new JsonSerializerSettings();
settings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
Locator.CurrentMutable.RegisterConstant(settings, typeof(JsonSerializerSettings));
It may be worth filing in issue in the Akavache repo to request more documentation for customization of serialization settings - the above works, but was guesswork and a little bit of source code investigation.
I'm using free boilerplate (ASP.NET Core MVC & jQuery) from this site https://aspnetboilerplate.com/Templates
Is it possible to add new language support?
I already add localized .xml file, update 'abplanguages' table in database but it is not working. I'm changing language but text is still in english. The same situation with predefined languages already shipped with boilerplate like 'espanol-mexico' is not working but when I pick 'french' the page is translated.
This is weird because in documentation said it can be done.
https://aspnetboilerplate.com/Pages/Documents/Localization#extending-localization-sources
I wonder is it free template restriction?
inject IApplicationLanguageManager interface and use AddAsync() method to add a new language.
private readonly IApplicationLanguageManager _applicationLanguageManager;
public LanguageAppService(
IApplicationLanguageManager applicationLanguageManager,
IApplicationLanguageTextManager applicationLanguageTextManager,
IRepository<ApplicationLanguage> languageRepository)
{
_applicationLanguageManager = applicationLanguageManager;
_languageRepository = languageRepository;
_applicationLanguageTextManager = applicationLanguageTextManager;
}
protected virtual async Task CreateLanguageAsync(ApplicationLanguageEditDto input)
{
if (AbpSession.MultiTenancySide != MultiTenancySides.Host)
{
throw new UserFriendlyException(L("TenantsCannotCreateLanguage"));
}
var culture = CultureHelper.GetCultureInfoByChecking(input.Name);
await _applicationLanguageManager.AddAsync(
new ApplicationLanguage(
AbpSession.TenantId,
culture.Name,
culture.DisplayName,
input.Icon
)
{
IsDisabled = !input.IsEnabled
}
);
}
public static class CultureHelper
{
public static CultureInfo[] AllCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
public static bool IsRtl => CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft;
public static bool UsingLunarCalendar = CultureInfo.CurrentUICulture.DateTimeFormat.Calendar.AlgorithmType == CalendarAlgorithmType.LunarCalendar;
public static CultureInfo GetCultureInfoByChecking(string name)
{
try
{
return CultureInfo.GetCultureInfo(name);
}
catch (CultureNotFoundException)
{
return CultureInfo.CurrentCulture;
}
}
}
public class ApplicationLanguageEditDto
{
public virtual int? Id { get; set; }
[Required]
[StringLength(ApplicationLanguage.MaxNameLength)]
public virtual string Name { get; set; }
[StringLength(ApplicationLanguage.MaxIconLength)]
public virtual string Icon { get; set; }
/// <summary>
/// Mapped from Language.IsDisabled with using manual mapping in CustomDtoMapper.cs
/// </summary>
public bool IsEnabled { get; set; }
}
I figure it out. In my case it was incorrect build action property. In VS right click on localization source file: *.xml file -> Advanced -> Build action: Embedded resource.
Can I write code in startup.cs...Configuration method to call my DataAccess layer and/or some other class to assign data to my static class after reading the configurations either from DB or from AppSettings from web.config file to read all my app configurations during the startup. I've tried to access my Static Class in startup.cs by adding reference to the library where my class resided, but I'm not able to access it in my asp.net MVC4 app.
namespace CAS.Common
{
public static class CommonConfiguration
{
public static string CDSRestClient { get; set; }
public static string ClientIdValue { get; set; }
public static string ClientSecretValue { get; set; }
}
}
Code from Startup.cs
using System.Configuration;
using CAS.Common;
namespace myWebApp
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
//This is the intended code, which I'm not able to do as I'm not able to access my static class here.
CommonConfiguration.CDSRestClient = ConfigurationSettings.AppSettings["CDSRestClient"].ToString().Trim();
CommonConfiguration.ClientIdValue = ConfigurationSettings.AppSettings["clientIdValue"].ToString().Trim();
CommonConfiguration.ClientSecretValue = ConfigurationSettings.AppSettings["clientSecretValue"].ToString().Trim();
}
}
}
Can anyone tell me what am I doing wrong here.
I am using NHibernate 3.3. I have a case where I want to insert a calculated column which is not referenced.
My Domain Entity can be reduced to the form
public class Location
{
public virtual IPoint GeoLocation {get;set;}
}
public class MappingOverride : IAutoMappingOverride<Location>
{
public void Override(AutoMapping<Location> mapping)
{
mapping
.Map(e => e.GeoLocation)
.Column("GeoLocation")
.CustomSqlType("geography")
.CustomType<MsSql2008GeographyType>;
}
}
The table column is of type 'Geography`
However it errors out as
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at GeoAPI.GeometryServiceProvider.GetLoadableTypes(Assembly assembly)
at GeoAPI.GeometryServiceProvider.ReflectInstance()
at GeoAPI.GeometryServiceProvider.get_Instance()
at NetTopologySuite.Geometries.Geometry.set_SRID(Int32 value)
It says that it needs Antrl.Runtime, but a very old version. All the Antrl.Runtime nuget packages out there have a different assembly identifier.
Could not load file or assembly 'antlr.runtime, Version=2.7.6.2, Culture=neutral, PublicKeyToken=1790ba318ebc5d56' or one of its dependencies. The system cannot find the file specified.
I worked on a separate project where I used map by code convention and it works without any reference to Antrl.Runtime.
Need help to point myself in the right direction...
As a separate sample project I tried something which worked, WHICH DID NOT WORK in the actual ASP.NET MVC project.
Definition of Class
public class Location : IEntity
{
public virtual int Id { get; protected set; }
public virtual string LocationName { get; set; }
public virtual IPoint GeoLocation { get; set; }
}
Mapping
public class LocationMapping : IAutoMappingOverride<Location>
{
public void Override(AutoMapping<Location> mapping)
{
mapping.Map(x => x.LocationName).Column("Name");
mapping.Map(x => x.GeoLocation).Column("GeoLocation")
.CustomType<MsSql2008GeographyType>();
}
}
Test
public class WhenSavingGeoLocation : BasePersistanceTest
{
[Test]
public void Save()
{
this.Session
.SaveOrUpdate(new Location {
LocationName = "Category 01",
GeoLocation = new Point(-72.12, 32.2323234) { SRID = 4326 }
});
}
}
NHibernate.Spatial uses NetTopologicalSuite which itself is a derivative of GeoAPI
The GeoAPI library defines an interface GeoAPI.Geometries and while loading / searching the correct implementation in the current project was failing with the Antlr error in the MVC project.
It was however able to fetch the NetTopologySuite.NtsGeometryServices implementation in the separate sample project. The actual code in GeoAPI which searches for the implementation goes like
private static IGeometryServices ReflectInstance()
{
#if !PCL
var a = AppDomain.CurrentDomain.GetAssemblies();
foreach (var assembly in a)
{
// Take a look at issue 114: http://code.google.com/p/nettopologysuite/issues/detail?id=114
if (assembly is System.Reflection.Emit.AssemblyBuilder) continue;
if (assembly.GetType().FullName == "System.Reflection.Emit.InternalAssemblyBuilder") continue;
if (assembly.GlobalAssemblyCache && assembly.CodeBase == Assembly.GetExecutingAssembly().CodeBase) continue;
foreach (var t in GetLoadableTypes(assembly))
{
if (t.IsInterface) continue;
if (t.IsAbstract) continue;
if (t.IsNotPublic) continue;
if (!typeof(IGeometryServices).IsAssignableFrom(t)) continue;
var constuctors = t.GetConstructors();
foreach (var constructorInfo in constuctors)
{
if (constructorInfo.IsPublic && constructorInfo.GetParameters().Length == 0)
return (IGeometryServices)Activator.CreateInstance(t);
}
}
}
#endif
throw new InvalidOperationException("Cannot use GeometryServiceProvider without an assigned IGeometryServices class");
}
}
This gets called when setting the SRID on the geometry. I am guessing that my MVC project has a reference to an assembly which makes this look for Antlr.
There were some suggestions of adding a redirect for to newer Antlr assembly. I tried that as well but the error still kept repeating.