开发者

Why Application.LocalUserAppDataPath throwing InvalidDeploymentException "Application identity is not set."

开发者 https://www.devze.com 2023-02-20 23:42 出处:网络
I have a simple program here that demonstrate the problem i am having. I have a library i am trying to use which is .net and develop for x86/32bit. Now my window in 64bit and visual studio was give er

I have a simple program here that demonstrate the problem i am having. I have a library i am trying to use which is .net and develop for x86/32bit. Now my window in 64bit and visual studio was give error in debuging that that image format is not right so i changed the build target to x86. Now i am getting another error which occure when LocalUserAppDataPath is accessed.

    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Console.WriteLine(System.Windows.Forms.Application.LocalUserAppDataPath);
    }

Does anyone 开发者_StackOverflow中文版have any idea how to fix this. If I run it without debugger it work ok but within visual studio debugger it give exception.


Tracing through the framework using Reflector:

public static string LocalUserAppDataPath
{
   get
   {
      ...
      if (ApplicationDeployment.IsNetworkDeployed)

which calls:

public static bool IsNetworkDeployed
{
   get
   {
      ...
      ApplicationDeployment currentDeployment = CurrentDeployment;

which calls:

public static ApplicationDeployment CurrentDeployment
{
   ...
   get
   {
      ActivationContext activationContext = AppDomain.CurrentDomain.ActivationContext;
      ...
      fullName = activationContext.Identity.FullName;

      if (string.IsNullOrEmpty(fullName))
      {
         throw new InvalidDeploymentException(Resources.GetString("Ex_AppIdNotSet"));
      }

So check if AppDomain.CurrentDomain.ActivationContext is assigned.

And if it is, check that .Identity.Fullname is something.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号