Xamarin Android error: <identifier> expected package #string - c#

In my app I tried reducing the amount of places I needed to update a string name, so I added a string in the Resources/values/Strings.xml file, but when I tried to test my build I got a weird error that I coudnt find a solution on, and have no idea why its doing that.
Someone know anything about this?
heres the xml code:
<resources>
<string name="service_name">ITMNotificationService</string>
</resources>
Using it in a Service attribute:
[Service (Label = "#string/service_name"
, Name = "#string/service_name"
, Icon = "#drawable/ITMIcon"
)]
And the error in the console;

The Name parameter for the ServiceAttribute is defining the Java class name that will be used in the ACW that is generated at compile time.
Thus the literal string of #string/service_name can not be used for a Java class name as that is invalid. Typically this would be the fully-qualified class name that includes your package id, ie.
Name = "com.sushihangover.coolapp.mywickedservice"
You could define this via a C# const string, but not an Android resource-based string value.
Note: You do not need to define the Name and Xamarin will auto-generated one via an MD5 hash routine. You then use typeof instead of the Java class name when calling the StartService method.

Related

How to access WCF in a IIS using a .Net Standard class

I built a WCF component resident in IIS. I have tested it and it appears to work correctly, however I'm trying to access it via the .NET Standard Class without success.
Could someone exemplify how we are expected to set C# commands to access the WCF methods?
The Visual Studio 2017 'Add Connected Service' dialogue with C# was used in a .NET Standard 2.0 Class.
Further detail
In reference.cs file there is
public interface IAvisaWCF
[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAvisaWCF/DoAccess", ReplyAction="http://tempuri.org/IAvisaWCF/DoAccessResponse")]
System.Threading.Tasks.Task DoAccessAsync(string INT_IdFisico, int INT_Id, int DI_ID, string DI_IDFisico, char Numero_Leitor, string Mobile_EMEI);
public partial class AvisaWCFClient : System.ServiceModel.ClientBase<AvisaWCFRef.IAvisaWCF>, AvisaWCFRef.IAvisaWCF
{
public System.Threading.Tasks.Task DoAccessAsync(string INT_IdFisico, int INT_Id, int DI_ID, string DI_IDFisico, char Numero_Leitor, string Mobile_EMEI)
{
return base.Channel.DoAccessAsync(INT_IdFisico, INT_Id, DI_ID, DI_IDFisico, Numero_Leitor, Mobile_EMEI);
}
In the Net Standard Class (stantiated in a Android Class) I had instantiated the component and Called de Async Method, like this;
AvisaWCFRef.AvisaWCFClient oComp = new AvisaWCFRef.AvisaWCFClient();
oComp.DoAccessAsync(Int_IdFisico, Int_Id, DI_ID, DI_IdFisico, Numero_Leitor, Mobile_EMEI);
The system then gave me the following error:
Unhandled Exception:
System.ServiceModel.FaultException`1 [[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version = 2.0.5.0,
Culture = neutral, PublicKeyToken = 31bf3856ad364e35]]:
An error occurred during deserialization of the request message body for the DoAccess operation.
The OperationFormatter encountered an invalid message body.
It was hoped to find 'Element' node with name 'DoAccess' and namespace 'http://tempuri.org/'.
Found element node with name 'DoAccessAsync' and namespace 'http://tempuri.org/' occurred
Could someone exemplify how I'm supposed to set C# commands to access the WCF methods?

How to rename a property in Xamarin Binding Library

I'm trying to build an android binding library for LINE SDK (a SNS service popular in Asia area). I added the jar file from the SDK into my project but it fails to compile because the creators of the SDK just happen to use the same name for a class and its property.
This is part of the C# code that the project generated from the jar file
public partial class AccessToken : global::Java.Lang.Object {
// Metadata.xml XPath field reference: path="/api/package[#name='jp.line.android.sdk.model']/class[#name='AccessToken']/field[#name='accessToken']"
[Register ("accessToken")]
public string AccessToken {
get { /* ... */ }
set { /* ... */ }
}
//...
}
Now simply put, I want to know how I can rename this property "AccessToken". I tried adding some commands in Metadata.xml but it had no effect. Here's a line of what I've written for reference
<attr path="/api/package[#name='jp.line.android.sdk.model']/class[#name='AccessToken']/field[#name='accessToken']" name="propertyName">AccessTokenString</attr>
I'd be grateful if somebody could help me out. I'm totally lost here.
What #SuavePirate suggests will not work completely (at least not now).
If you use name it will also rename the Register attribute parameter as [Register ("AccessTokenString")] instead of [Register ("accessToken")]. So as it states here it will be no longer possible for the Xamarin.Android binding class to access that property because it is not bound to an existent Java member.
To properly change the managed name of a wrapped member, it is necessary to set the managedName attribute, i.e.:
<attr path="/api/package[#name='jp.line.android.sdk.model']/class[#name='AccessToken']/field[#name='accessToken']" name="managedName">AccessTokenString</attr>
I believe the only issue is that "propertyName" should just be "name":
<attr path="/api/package[#name='jp.line.android.sdk.model']/class[#name='AccessToken']/field[#name='accessToken']" name="name">AccessTokenString</attr>

Understanding Error Report

Can anyone help me understand this error report:
Error: Object reference not set to an instance of an object.
at Project.Web.Config.Data.DataProvider.get_ConfigSettingsConnectionString()
at Project.Web.Config.Data.DataProvider.GetConfigSettings()
at Project.Web.Config.ConfigBase.GetConfigSettings()
at Project.Web.Config.ConfigBase.GetConfigSettingValue(String configName)
at Project.Web.Config.ConfigBase.StringConfigSetting(String configName, String defaultValue)
at Project.Web.Config.Brands.get_BrandsConnectionString()
at Project.Web.Engine.Brands.Data.BrandsDataProvider.GetBrandByHostname(String hostname)
at Project.Web.Engine.Brands.Brands.CurrentBrand()
at Project.Web.Engine.Placeholders.BrandedResource.GetHtmlContent(String resourcePostingName, String resourceName, String cultureCode)
at Project.BWMembership.TranslationHelper.GetTranslation(String sResourcePostingName, String sResourceName, String sCultureCode)
at Project.BWMembership.TranslationHelper.TranslateCountries(ListResponse[] arrCountries, String sCultureCodes)
at ASP.update_aspx.Bind(Member oMembership, Order oOrder) in c:\Projects\Project\zsys_admin\update.aspx:line 82
at ASP.update_aspx.Page_Load(Object sender, EventArgs e) in c:\Projects\Project\zsys_admin\update.aspx:line 58
I know it is telling me there is a null object, and it is coming from:
at Project.Web.Config.Data.DataProvider.get_ConfigSettingsConnectionString()
And I know the rest of the data is a list of methods leading to the error
I am trying to identify what the null object is and how to resolve it.
I know each line corresponds to calling a method, for example, I can call the method:
Project.BWMembership.TranslationHelper.TranslateCountries(ListResponse[] arrCountries, String sCultureCodes)
By typing that in my code. I know this method is in the DLL:
Project.BWMembership
and in the class:
TranslationHelper
and the method is called:
TranslateCountries(ListResponse[] arrCountries, String sCultureCodes)
But when I type:
Project.Web.Config.Data.DataProvider.get_ConfigSettingsConnectionString()
It does not recognize this.
Visual studio will offer me the code up to:
Project.Web.Config
But from there will stop.
Is it the case that Config is a class name, and Data is an instance of a different DLL included in Project.Web and being instantiated in this method?
If so, can I assume there is a class called DataProvider in this DLL that has a method called Get_ConfigSettingsConnectionString() ?
and if this is the case, does this mean essentially this is trying to find some data that does not exist? For example it is looking for a connection string that either does not exist in the existing web config, or is looking for a web config that does not exist?
Or is it that Project.Web.Config refers to the config file of the DLL?
Which opens up a whole new set of questions!
There's no method named get_ConfigSettingsConnectionString(), but there's a propery named ConfigSettingsConnectionString (see this SO answer) in class DataProvider.
Generally speaking, you cannot infer the exact name of the DLL from full type name: for example, System.Int32 comes from mscorlib.dll.
Now, what the error you are having is telling you is that there's something inside get part of said property that is accessing a null object reference.

Invalid Resx file. Could not load type error why?

I'm getting designer error on code:
The Component i'm willing to define a List of properties for:
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
namespace TestProjectForProperty.Test
{
public class MyTreeView : TreeView
{
private List<TypeDescriptorBase> _descriptorsAvailable = new List<TypeDescriptorBase>();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<TypeDescriptorBase> DescriptorsAvailable
{
get { return _descriptorsAvailable; }
set { _descriptorsAvailable = value; }
}
}
}
The Descriptor itself:
using System;
namespace TestProjectForProperty.Test
{
[Serializable]
public class TypeDescriptorBase
{
public string Name { get; set; }
public override string ToString()
{
return Name;
}
}
}
I am getting the following error if i try to use the component for example on a form and add any items on the property sheet or in the component's constructor to the DescriptorsAvailable property
Error 1 Invalid Resx file. Could not load type
System.Collections.Generic.List`1[[TestProjectForProperty.Test.TypeDescriptorBase,
TestProjectForProperty, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 which is used in the .RESX file.
Ensure that the necessary references have been added to your project.
Line 134, position 5. ...\visual studio
2010\Projects\TestProjectForProperty\TestProjectForProperty\Form1.resx 134 5 TestProjectForProperty
In the Resx file there is data field with base64 encoded stuff inside when this error is present.
I have been searching for an answer, but the best i got is to restart everything, it didn't help me, do you guys have any suggestions? I'm using .net 4 client and visual studio 2010
In my experience, this is due to a change of version of a referenced library, or a change of the lib itself, which contains the backing type of a property you have defined in your user control. The solution is to "force" the visual studio designer to re-initialize it's designer code for that type, and not expect to retrieve a "canned" version of it from the .resx file of the control.
1) Delete the offending data section in the .resx file of your control. This will be a section in the xml of the .resx file associated with your user control, which has a node: <data></data> - the name attribute will be set to whatever you've named that object in the properties of whatever you added this type to. The <data>/data> section contains a base64 encoded string that is the encoded form of the name and version of the library the type comes from. This is where the problem ism, because it now contains an encoded version of the library and/or version number you are no longer referencing in order to include the type. Delete the entire <data>/data> section, from opening to closing tag, save the change and close the file. Now the "artifact" is gone.
2) Now find the place in the designer file for your control, where the type is instantiated; this is initialization code generated for you by visual studio, and it is the place that is expecting to load a "canned" definition of the type from the base64 encoded string contained within the .resx file. The line will look something like this:
this.myCtrlFoo.MyPropertyFroo = ((MyNamespaceFoo.MyTypeFoo)(resources.GetObject("myCtrlFoo.MyPropertyFroo")));
...now just replace the resources.GetObjec call with the instantiation of a new instance of the appropriate type like so:
this.myCtrlFoo.MyPropertyFroo = ((MyNamespaceFoo.MyTypeFoo)(new MyNamespaceFoo.MyTypeFoo()));
...now save the change to the file, close it, rebuild, and everything should now build & run OK.
Put the MyTreeView and TypeDescriptorBase classes into another project and reference it from your GUI project will resolve the issues.
I'm not sure why exactly the problem occurs - I guess it has something to do with the way the serializing process is generating the base64 string for the DescriptorsAvailable Property. Maybe somebody else can give us some insight.
I've struggled quite a bit with this; I have three user controls that all expose the same non-designer property, but for some reason, any change to two of the three would instantly cause the next build to fail with this same issue. This is in VS 2015.
I wound up having to add the following two attributes to the property that kept expanding in the resx file, and it hasn't occurred since. It works for me because they're not available in the designer anyway.
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
For me, this error occured when I used a custom class as a property for the user control. When I switched from property to traditional get- and set- methods, the error disappeared. I guess this is because properties are already compiled at design-time, so when you build the whole project, a new version of the custom class is compiled which is separate from the one of the control, and the reference is broken.
For me, with the custom class Inventory, all I had to do was to switch from this property-based approach:
public Inventory Resources {get;set;}
to this method-based approach:
private Inventory resources;
public Inventory getResources() { return resources; }
public void setResources(Inventory newResources) { resources = newResources; }
I hope this helps someone, as I've been spending some hours on figuring it out.
In my case I've got the error : "error MSB3103: Invalid Resx file. The specified module could not be found" executed in a light windows container based on mcr.microsoft.com/powershell instead of mcr.microsoft.com/windows:1909 (was working fine on 1909).
The error was on a ressource icon that was compressed with PNG inside.
It can be checked by opening the ressource on visual studio : Project > Properties > Ressources.resx, select icons, double click on the icon, check the end of the title that is either "..,BMP]" or "...,PNG]").
Updating the icon with an uncompressed format solve the "Invalid Resx file" issue.
I stumbled across this question today whilst looking for the solution to a similar issue.
Unfortunately none of the above worked for me, however my issue turned out to be that I had different versions of the .NET Framework for different projects. For example;
Project A - .NET Framework 4.7.2
Project B - .NET Framework 4
Where Project B was referencing Project A. Solution was simply to change the .NET Framework version of Project B to 4.7.2 (in my case) and hey presto the issue was resolved.
A shame Visual Studio doesn't provide a more helpful error message in this case, but something to look out for!

How to execute SQLCLR UDF added directly to SSDT sqlproj and resolve reference error SQL71501

I have been trying to find the answer to this simple question - but so far couldn't figure it out.
Let say I have MyDb.sqlproj, with various sql content (sprocs, views, trigger, etc).
I have added a new UDF through Add-> New item -> SQL CLR C#, User Defined Function.
For example:
namespace MyNameSpace
{
public class MyClass
{
[SqlFunction(DataAccess = DataAccessKind.Read)]
//I use different attributes here, but it doesn't matter
public static int Method1()
{
return 0;
}
}
}
In MyDb.sqlproj Properties, SQLCLR tab MyDb is the name of assembly and default namespace
In my sql code I call the clr method using EXTERNAL NAME:
CREATE PROCEDURE ClrMethod1
RETURNS [int] WITH EXECUTE AS CALLER
AS EXTERNAL NAME [MyDb].[MyNamespace.MyClass].[Method1]
I seem to tried everything to get the last line to compile. It cannot resolve the reference and get:
SQL71501: Function: [name of my sql function] has an unresolved
reference to Assembly [MyDb]
Please point me to the right way to get it working. What could I be missing?
I am using VS2010 SP1 and latest version of SSDT
You must add your compiled DLL containing your CLR code as a Reference. So under your MyDb SSDT project->References(right click)->Add Reference, browse to the DLL.
You could probably get away with referencing the project instead of the DLL if you had the CLR(class library) project in the same solution, but in my case I am referencing a DLL(compiled for a seperate solution).
As far as the format of the AS EXTERNAL NAME line:
AS EXTERNAL NAME [AssemblyName].[ClassName].[FunctionName]
Note: For CLR objects I remove the namespaces from around my classes/code just to simplify things, because this step is usually the most problematic. It is easy to confuse the AssmeblyName/DLL Name/Namespace. The AssemblyName is found in your CLR class library project by accessing the Project Properties->Application->"Assembly Name:". I would remove any non alpha-numeric/spaces from it just to simplify the name and rule out that as a problem.
So I would try that, and once you get that working, if you really want namespaces, then you can add the namespace and figure out the syntax from there, and at least you know the other parts are correct.
Ok reallized that you have a *.cs file actually inside the same SSDT project. so in that case if your code is this:
CS file:
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString SqlFunction1()
{
// Put your code here
return new SqlString (string.Empty);
}
}
SQL file:
CREATE PROCEDURE ClrMethod1
RETURNS [int] WITH EXECUTE AS CALLER
AS EXTERNAL NAME [MyDB].[UserDefinedFunctions].[SqlFunction1]
This compiles for me. Note: Again no namespace was used. When I did Add New Item... the generated code did not come with a namespace.

Categories

Resources