In order to be able to translate my data annotations in my model with a resource file, I saw that many people recommend the solution offered by jgauffin.
However, when I follow the localization tutorial my project cannot launch.
The problematic code is this one, which is supposed to go in the Global.asax.cs file:
ModelValidatorProviders.Providers.Add(
new LocalizedModelValidatorProvider(stringProvider)
);
It says that the LocalizedModelValidatorProvider constructor does not take any arguments, which is also shown by other tutorials.
But when I change the line like this:
ModelValidatorProviders.Providers.Add(
new LocalizedModelValidatorProvider()
);
I get the following error in the browser:
Attempted to access an element as a type incompatible with the array.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.
The griffin.mvccontrib packages were installed with NuGet under Visual Studio 2012. Any idea what I am doing wrong ?
You might find this link helpful
Here is how I did the registration in the above link:
ResourceStringProvider myResouceFile = new ResourceStringProvider(ModelsResources.ResourceManager);
//ModelsResources is my resource file generated class
GriffinStringsProvider griffinStringsProvider = new GriffinStringsProvider(myResouceFile);
ValidationMessageProviders.Clear();
ValidationMessageProviders.Add(griffinStringsProvider);
ModelMetadataProviders.Current = new LocalizedModelMetadataProvider(myResouceFile);
ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new LocalizedModelValidatorProvider());
Make sure you are including the right assemblies
using System.Resources;
using Griffin.MvcContrib.Localization;
using Griffin.MvcContrib.Localization.ValidationMessages;
Also the assembly for your Resource file.
Related
Im trying to use the OData Connected Service in Visual Studio to connect to a OData Feed in Bridge (RESO Feed).
However, If I try and pull the metadata directly from a URL, it has errors Adding OData Connected Service to the project failed: Could not get CLR type name for EDM type 'memberMediaEnums.ResourceName'
So I went ahead and downloaded the XML file and tweaked it to get rid of the errors and warnings. This includes Removing Entity references with no parents and removing attributes that were not supported like Precision.
Once its all loaded and the reference file is created I tried pulling data. The endpoint works and data is retrieved, but it is not thrown into the object as i would expect.
IEnumerable<Property> properties= await context.Property.ExecuteAsync();
foreach (var property in properties) //Errors trying to make a property
{
Console.WriteLine("{0} {1}", property.YearBuilt, property.ListPrice);
}
When I try and loop over the object I get this error:
The context URI 'https://api.bridgedataoutput.com/api/v2/OData/imls2/$metadata#Property' is not valid for the expected payload kind 'Resource'.
Where I am confused, is in the name Resource There is no object or entity in the Reference file or in the XML scheme that references that word. I'm not sure if its coming from OData services or the reference file it created. The call stack does not contain anything but the exact line of the loop.
Any insights would be helpful but i know its a long shot. Let me know if I need to provide more details.
Thanks
Upgrading Microsoft.Bot.Builder.LanguageGeneration from 4.14.1 to 4.15.0 results in new errors about the fromFile() method. Couldn't find any solution or similar issues on the internet yet. This holds us from upgrading so any feedback is welcome.
/UnitTests/bin/Debug/net5.0/Resources/Lg/General.lg line 25:2 - line 25:39: Error occurred when parsing expression 'fromFile('../Cards/HelpCard.json')'. fromFile does not have an evaluator, it's not a built-in function or a custom function.
This release introduces a global flag called
"Templates.EnableFromFile" that indicates whether the Adaptive
Expression fromFile function is allowed in LG templates. If an
application had previously made use of this function, it is now
required to add the line "Templates.EnableFromFile = true;" to the
Startup.cs code.
from botbuilder-dotnet/releases
Adding it in Startup.cs (or Program.cs) didn't help. I had to put it in the constructor of the service where I used the Templates class.
For someone who needs sample on how to add it.
Add it like this in startup.cs-> ConfigureServices method.
Also on lg file - you dont have to create manually lg file - it will be generated in backend.
You just have to add your content in bot responses which is the content it will be generated in lg file in backend - you can open the same solution in visual studio and see it.
I am trying to generate an OpenApi service reference in Visual Studio 2019. .Net 5.0.
Right clicking project >Add>Connected Services>+ Service References
I am using NetDocs api "https://api.vault.netvoyage.com/v2/swagger/docs/v2".
Result: I get generated c# client code but it is duplicating the types with the errors below.
Severity Code Description Project File Line Suppression State
Error CS0102 The type 'v2Client' already contains a definition for '_settings' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4941 Active
Error CS0579 Duplicate 'System.CodeDom.Compiler.GeneratedCode' attribute OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4936 Active
Error CS0102 The type 'v2Client' already contains a definition for '_baseUrl' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4939 Active
Error CS0102 The type 'v2Client' already contains a definition for '_httpClient' OpenAPITest C:\Users\dryfus\source\repos\OpenAPITest\obj\v2Client.cs 4940 Active
Is there a way I can get this to work with the connector way without the duplicates? Or even cli? Any suggestions on why it is creating the duplicates?
I had the same issue, it turns out the code generation didn't like enpoints with an underscore in its operationId. Lucky for me, the service I was consuming was also part of our code, so I could just go to the Swagger configuration in the API side and change the CustomOperationIds setting.
I downloaded and use NSwagStudio to generate the client code and did not have the same issue that the Visual Studio connector had when generating the code.
https://github.com/RicoSuter/NSwag/wiki/NSwagStudio
It is actually caused by this option
OperationGenerationMode:MultipleClientsFromOperationId
MultipleClientsFromOperationId : Multiple clients from the Swagger operation ID in the form '{controller}_{action}'
However, if your classname is set as a static name, it will cause an error like you have.
The correct solution should be change the classname to something like
ClassName="{controller}ServiceClient"
So it will generate different classes.
I'm trying to get the Globalize.js library to work under an ASP.NET MVC 5 application + unobstrusive validation. Specifically, I have most of the libraries and requirements working as per the post https://stackoverflow.com/a/25289555/1838819. However, when validation actually kicks in on an input tag of type="text" but contains a decimal number, I get the following error;
Uncaught Error: E_MISSING_BUNDLE: {"locale":"en"}
at createError (cldr.js:339)
at validate (cldr.js:355)
at Cldr.main (cldr.js:669)
at numberNumberingSystem (number.js:450)
at numberPattern (number.js:1325)
at Function.Globalize.numberParser.Globalize.numberParser (number.js:1429)
at Function.Globalize.parseNumber.Globalize.parseNumber (number.js:1474)
at a.validator.methods.number (jquery.validate.globalize.min.js:1)
at a.validator.check (jquery.validate.min.js:4)
at a.validator.checkForm (jquery.validate.min.js:4)
I'm loading and configuring the library via;
$.when($.get("/Scripts/cldr/supplemental/likelySubtags.json"))
.done(function(result) {
Globalize.load(result);
Globalize.locale("en");
});
Which works and runs through fine until validation is attempted via;
$.validator.unobtrusive.parse(_form);
_form.validate();
if (_form.valid()) { // ** error thrown here
_uiModalConfirmForm.modal('toggle');
}
I'm nearly sure that I'm missing a load reference to locale/en.json or something very similar but finding that resource is seemingly next to impossible. The documentation for cldr (what Globalize currently uses as it's main source of localized data), is...self referential at best and quite frustrating to navigate. There are no specific NuGet packages for this either that I can find.
The documentation that I can find says that the resource should be compiled. Looking at the documentation for that compiler links back to the Gloablize documentation and further goes on about spinning up a test server, installing Node Package Manger or Bower and installing from there. Which...seems like overkill when all I want is a file. I haven't yet gone down this road as I'm hoping there's an easier, quicker method to locate the needed file.
Any help on actually configuring the resources for this library in Visual studio would be greatly appreciated.
CLDR-core: https://github.com/unicode-cldr/cldr-core
Globalize doc: https://github.com/globalizejs/globalize/blob/master/README.md
likelySubtags.json (weirdly difficult to find): https://github.com/unicode-cldr/cldr-core/blob/master/supplemental/likelySubtags.json
I have been given a WSDL with all the method requests and responses, and all the objects I'll need to use for creating a few web methods.
I've successfully added the WSDL as a "service reference" and I can see the methods and structures and can instantiate them. It all seems to be there. But, I have a problem: the project won't build after I add the WSDL. Here's the error message I am getting when Visual Studio tries to compile Reference.cs:
"Error 2 The type name 'ServiceReference1' does not exist in the type
'WSPELab.WSPELab' C:\Users\JJ\Documents\Visual Studio
2008\Projects\WSPELab\WSPELab\Service
References\ServiceReference1\Reference.cs 21 111 WSPELabSLN
Is it possible that I am receiving this error message because of a namespace error on my part?
Finally, one additional question: With the WSDL added, can I use the structures it contains directly? Or are they just "listings" for me to implement?
A WSDL is a machine-readable file that describes the methods and types exposed by a web service. Many IDEs, including Eclipse and Visual Studio, can import these and create programming language classes that match the definitions given in the WSDL.
For example, importing a WSDL in a Visual Studio C# project will create a Reference.cs file that contains these definitions. You have to instantiate and call these definitions the same as you do for any classes.
var webServiceReference = new WsdlNamespace.ClassDefinedInWsdl();
WsdlNamespace.ParamClassDefinedInWsdl dataToGet;
WsdlNamespace.ReturnCodeTypeDefinedInWsdl retCode = webServiceReference.MethodDefinedInWsdl("params expected by method", out dataToGet);
if (retCode == WsdlNamespace.ReturnCodeValueMeaningAllIsWell)
{
// use properties of dataToGet
}
Giving any more detail would require showing us the actual WSDL.