Visual Studio 2019 (16.3.4), Xamarin Forms 4.2.0.848062
I have the following in my Log On page:
<Entry
x:Name="Email"
StyleClass="Contrast"
Text="{Binding Email}"
Placeholder="{x:Static resources:ApplicationResources.Email}"
HeightRequest="45"
Keyboard="Email" />
My Resources are in a separate project and marked as "Embedded Resource". The Resources work fine including the one above. However, this one just happens to be the first Resource I access. It throws an exception:
System.IO.FileNotFoundException: 'Invalid Image'
on the following "Auto generated code" line in the Designer:
/// <summary>
/// Looks up a localized string similar to e-mail.
/// </summary>
public static string Email {
get {
return ResourceManager.GetString("Email", resourceCulture); // Exception here
}
}
Continuing on from the Exception and the resource string appears in the PlaceHolder as expected.
If I remove that PlaceHolder code, the same thing happens on the next Resource. But it only happens on the first Resource I access and it seems to work anyway?!?!?!
Why is it throwing the Exception at all?
Related
This is default VSPackage. I added only ProvideAutoLoad attributes.
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.Win32;
using Task = System.Threading.Tasks.Task;
namespace VSIXProject1
{
/// <summary>
/// This is the class that implements the package exposed by this assembly.
/// </summary>
/// <remarks>
/// <para>
/// The minimum requirement for a class to be considered a valid package for Visual Studio
/// is to implement the IVsPackage interface and register itself with the shell.
/// This package uses the helper classes defined inside the Managed Package Framework (MPF)
/// to do it: it derives from the Package class that provides the implementation of the
/// IVsPackage interface and uses the registration attributes defined in the framework to
/// register itself and its components with the shell. These attributes tell the pkgdef creation
/// utility what data to put into .pkgdef file.
/// </para>
/// <para>
/// To get loaded into VS, the package must be referred by <Asset Type="Microsoft.VisualStudio.VsPackage" ...> in .vsixmanifest file.
/// </para>
/// </remarks>
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
[Guid(VSPackage1.PackageGuidString)]
[ProvideAutoLoad(UIContextGuids.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(UIContextGuids.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
public sealed class VSPackage1 : AsyncPackage
{
/// <summary>
/// VSPackage1 GUID string.
/// </summary>
public const string PackageGuidString = "cca56365-4b14-4a96-9280-c30dce400195";
/// <summary>
/// Initializes a new instance of the <see cref="VSPackage1"/> class.
/// </summary>
public VSPackage1()
{
// Inside this method you can place any initialization code that does not require
// any Visual Studio service because at this point the package object is created but
// not sited yet inside Visual Studio environment. The place to do all the other
// initialization is the Initialize method.
}
#region Package Members
/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
/// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
/// <param name="progress">A provider for progress updates.</param>
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
// When initialized asynchronously, the current thread may be a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
}
#endregion
}
}
Looks like it's not being instanced. If I'm adding break point or Debug.WriteLine(...) then nothing happening. When I'm adding Command then also nothing. I only can see my extension in Extensions and Updates window.
I recorded the little video with step by step reproduction my problem:
https://youtu.be/B2T311Ug5FQ
What I should to do to my package gets instanced?
I started from the default package template and for me it turned out that adding the attribute
[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
to the package class made things work. Try going back to the default template and add that line, then debug.
To me this is a bug in the template. Templates should just work without needing to hunt around on stackoverflow for ages to find the magical missing incantation. Obviously you just want to hit the debug key and see the breakpoint hit, then build out from there.
I had this problem with an extension taken over from Visual Studio 2017, which was before taken over through all intermediate Visual Studio Versions, I think maybe created on VS2010. I changed two things or more, but I don't know which of these made it work.
Similar to satnhak above had to add
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionExists_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasMultipleProjects_string, PackageAutoLoadFlags.BackgroundLoad)]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasSingleProject_string, PackageAutoLoadFlags.BackgroundLoad)]
In my .csproj removed a line
<OldToolsVersion>14.0</OldToolsVersion>
I found these by comparing a newly created extension from template and comparing all properties (argh).
Also found out that after uninstalling the extension I had to start up Visual Studio one time with another solution to finish the uninstallation process completely. I guess it has a flag somewhere which blocks the instantiation of a newly installed one until this has been fully completed. Sorry all a bit fuzzy.
In any case also something good to know is that problems are logged in these locations:
%appdata%\Microsoft\VisualStudio\16.0_d1c373d5\ActivityLog.Setup.xml
%appdata%\Microsoft\VisualStudio\16.0_d1c373d5\ActivityLog.xsl
%appdata%..\Local\Temp\dd_VSIXInstaller_*.log
Every successful instantiation is logged in the last one.
My scenario was: I created a VSIX project in VS2022 and then added an AsyncPackage to it. I hadn't noticed that the VSIX project already contained another package.
The other AsyncPackage was both instantiated and initialized. Therefore, I removed the one I added and used the pre-existing one, problem solved.
I cannot find any documentation about it, but it looks that each VSIX only loads just one package.
see VSIX: how to pack two or more vspackage into a vsix
It is now 2022 and the template is still not fixed. Very happy I found this post after just a few hours of going insane.
adding
[ProvideAutoLoad(UIContextGuids80.NoSolution, PackageAutoLoadFlags.BackgroundLoad)]
to the main AsyncPackage made it load!
When I set the Image property of a Button control to point to an image in the Projects resource file, it shows up just fine in the application when I compile and run it, but if I try to load the form in the designer, it gives me an 3error message.
The type 'CoP.LAS.Properties.Resources' has no property named
'Adobe1'.
Although when I look in the auto-generated Resources file, it is clearly there:
namespace CoP.LAS.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(
"System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
// Other stuff...
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap Adobe1 { // <--- HERE!!!
get {
object obj = ResourceManager.GetObject("Adobe1", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
And the designer will not load the form unless I ignore this error, which removes the setting from the form code. The only way I have been able to fix this is to import the graphic into the project for each place in the project where I want to display it. This is, obviously redundant, as the image is being "imported" for every usage. I should be able to use images in the project's common resource file and still load the form into the designer.
What's going on here and how do I fix this.
I am trying to reduce app size and enabled "Link All Assemblies", but my app crashes with following error
MvvmCross.Platform.Exceptions.MvxException: Failed to construct and initialize ViewModel for type Japam.Core.ViewModels.MantraasViewModel from locator MvxDefaultViewModelLocator - check InnerException for more information
I tried
--linkskip=mvvmcross.platform.ios
--linkskip=mvvmcross.core
--linkskip=mvvmcross.platform
but no luck, kept preserve attribute at assembly level of my core pcl project.
Also added a couple of more methods in LinkerPleaseIncludefile
public void Include(MvvmCross.Platform.IoC.MvxPropertyInjection injection)
{
injection = new MvvmCross.Platform.IoC.MvxPropertyInjection();
}
public void Include(MvxDefaultViewModelLocator locator)
{
locator = new MvxDefaultViewModelLocator();
}
but no use, could somebody help me find out what is missing
MvvmCross.Platform.Exceptions.MvxException: Failed to construct and initialize ViewModel for type
Japam.Core.ViewModels.MantraasViewModel from locator
MvxDefaultViewModelLocator - check InnerException for more information
---> MvvmCross.Platform.Exceptions.MvxException: Problem creating viewModel of type MantraasViewModel --->
MvvmCross.Platform.Exceptions.MvxIoCResolveException: Failed to
construct MantraasViewModel --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. --->
MvvmCross.Platform.Exceptions.MvxIoCResolveException: Failed to
resolve parameter for parameter sqliteConnectionFactory of type
IMvxSqliteConnectionFactory when creating
Japam.Core.Services.DataServices.MantraService
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.GetIoCParameterValues
(System.Type type, System.Reflection.ConstructorInfo firstConstructor)
[0x00036] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\
Finally I found the issue, it's SQLite problem so I added below three commands and it started working hope this helps someone else
--linkskip=MvvmCross.Plugins.Sqlite
--linkskip=SQLite-net
--linkskip=MvvmCross.Plugins.Sqlite.iOS
I should kept SQLite earlier it self my last project I did kept SQLite but forgot this time
I had to take over an MVC 3 project from another developer. One of the first things he did was to stop the yellow screen of death so that all exceptions are only logged to a file. You now only get a generic message saying an error has occurred.
I would like to switch it back on (since it gets really annoying having to check through the logfiles the whole time) - how do I do this.
I checked through the web.config but I can't see where this happens.
I did try doing customerrors=off, but that didn't do anything. Also removed the global error handling attribute, didn't do anything.
On further clarification, it seems if an exception occurs in a controller I do get the yellow screen of death, but if it occurs in a (razor) view I just get a standard generic error.
You can see the web.config here
You can see the global.asax here
This question is a little old, but maybe this will help someone. In addition to setting <customerErrors mode="Off" />, also set this under <system.webServer>: <httpErrors errorMode="Detailed" />
<system.webServer>
<httpErrors errorMode="Detailed"/>
</system.webServer>
Normally you set this in web.config in the customErrors element under system.web.
Just try to set mode=Off:
<customErrors mode="Off" />
In Global.asax you can remove filters.Add(new HandleErrorAttribute()); from public static void RegisterGlobalFilters(GlobalFilterCollection filters).
As pointed out in the comments - the problem was with a Custom Base controller overriding the OnException Method.
None of this worked for me. Check if someone might have added code to clear the error in the application error event handler.
protected void Application_Error(object sender, EventArgs e)
{
Exception lastException = Server.GetLastError().GetBaseException();
Log.Error("Global.asax: WebApplication error", lastException);
//****Server.ClearError();
}
I created Windows Mobile Application and I loaded web service that contain one method (GetNumber). When I call this method from my emulator I got a following exception
An error message cannot be displayed because an optional resource assembly containing it cannot be found.
Can anyone help me. This is my code from WM Application, it is very siple.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MobileClientApp;
namespace MobileClientApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MobileClientApp.localhost.WebService m = new MobileClientApp.localhost.WebService();
int result;
bool resbool;
m.GetNumber(10, true, out result, out resbool);
label1.Text = result.ToString();
}
}
}
For a very good explanation:
http://blogs.msdn.com/b/netcfteam/archive/2004/08/06/210232.aspx
(excerpt from above)
There has been some confusion about the error message: "Could not find resource assembly". Basically, this means that there is some exception that has happened in the program. The error did not happen because it could not find the resource assembly. The resource assembly that it is searching for contains exception messages (strings) that would be helpful in debugging what went wrong with the program.
Since the user is never expected to see this error message if the program works as expected and all exceptions are handled appropriately, it was decided (due to size constraints) that the resource assembly that has these error strings are never put on a user's device. Thus the main target audience of these error strings are developers who would like to debug issues. Hence, when you do an F5 deploy onto the device, the System.SR.dll assembly which have these error strings are copied to the device and the developer can see the error messages. But in case .Net Compact Framework is installed from a redistributable or you are using .Net Compact Framework that come with the device (as a user of the device would be doing), the System.SR.dll is not present on the device. Hence, if the application did come upon an exceptional condition that wasn't handled by the application, this "Could not find resource assembly" message would be shown to the user.
If you are not using Visual Studio F5 deploy to the device and would still like to see the exception messages, you can achieve this by taking the System_SR_[Language].CAB where [Language] corresponds to the language in which you want to see the error message to appear and clicking on the cab file to install it
Sounds like you are missing an assembly in your deployment.